class Component {
constructor(element) {
this.element = element;
this.button = this.element.find('.button');
this.bindListeners();
}
onButtonClick() {
alert();
}
bindListeners() {
// Вариант 1
this.button.addEventListener('click', () => {
this.onButtonClick()
})
// Вариант 2
this.button.addEventListener('click', this.onButtonClick.bind(this))
}
}
<div>${require('./components/gallery.html')}</div>