Is it recommended to call a child method from a parent class in JavaScript? In the given example in BaseComponent.js, calling this.constructHtml() is returning undefined. What could be causing this issue? Thank you!
script.js
import Header from './components/Header.js';
const headerEl = document.querySelector('.header');
const header = new Header(headerEl);
header.render();
Header.js
import BaseComponent from './BaseComponent.js'
export default class Header extends BaseComponent {
constructor(element)
{
super(element);
this.element = element;
}
constructHtml() {
return
`
<header>
<h1>Todo App</h1>
</header>
`;
}
}
BaseComponent.js
export default class BaseComponent {
constructor(element) {
this.element = element;
}
render(){
this.element.innerHTML += this.constructHtml();
}
}