There is an input type = "date" when it is changed, a value is calculated, how to pass this value to a child class. I read the certificate, the parameters are passed there, and if I calculate the property, then how can I get it in the child class in order to further perform the following operations with it

<body> <div class="input"> <input type='date' /> </div> <div class="containerForLastUpdateRecordAndPeriodItems"></div> <script> class dateInput { constructor() { this.input = document.querySelector("input[type='date']"); this.input.onchange = this.onChange; } onChange(event) { this.inputValue = event.target.value; console.log('В датаИмпуте', this.inputValue) this.updateTime = new Date(); console.log('В updateTime', this.updateTime) return this.inputValue; } } class dateRange extends dateInput { constructor() { super(); this.container = document.querySelector('.containerForLastUpdateRecordAndPeriodItems'); } onChange() { console.log(this.inputValue); this.createPeriod(this.inputValue); } createPeriod(date) { let newDate = date; console.log(newDate); newDate.year = newDate.year + 1; return { start: date, end: newDate } } } const range = new dateRange(); </script> </body> 

    1 answer 1

    In your case, you completely overwrite the method without using the method of the parent class.

    You need to use the reserved word super

     class dateInput { constructor() { this.input = document.querySelector("input[type='date']"); this.input.onchange = this.onChange.bind(this); // иначе потереяте контекст } onChange(event) { this.inputValue = new Date(event.target.value); console.log('В датаИнпуте', this.inputValue) this.updateTime = new Date(); console.log('В updateTime', this.updateTime) } } class dateRange extends dateInput { constructor() { super(); this.container = document.querySelector('.containerForLastUpdateRecordAndPeriodItems'); } onChange(event) { super.onChange(event); // вызываем метод родительского класса console.log(this.inputValue); // this.inputValue уже доступен const result = this.createPeriod(); console.log(result); } createPeriod() { let newDate = this.inputValue; // не обязательно передавать параметры newDate.setYear(+newDate.getFullYear() + 1); // это делается так console.log(newDate); return { start: this.inputValue, end: newDate } } } const range = new dateRange(); 
     <body> <div class="input"> <input type='date' /> </div> <div class="containerForLastUpdateRecordAndPeriodItems"></div> </body>