Можно сделать как-то так (я в js не особо умею)
class Button {
getDOMInstance() {
if (!!this.DOMInstance)
return this.DOMInstance;
this.DOMInstance = document.createElement('button');
this.__setListeners();
return this.DOMInstance;
}
renred() {
document.body.appendChild(
this.getDOMInstance()
);
}
__setListeners() {
document.addEventListener('some-event', this.__someEventListener);
}
__someEventListener(e) {
alert(`${e.type} was triggered`);
}
__removeListners() {
document.removeEventListener('some-event', this.__someEventListener);
}
}
class LanguageSwitcher {
__onChange() {
document.dispatchEvent(new CustomEvent('some-event'))
}
}