Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created April 24, 2024 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/b4f79d3d063b85c1168187f6cc9eeaca to your computer and use it in GitHub Desktop.
Save Kcko/b4f79d3d063b85c1168187f6cc9eeaca to your computer and use it in GitHub Desktop.
class Test {
constructor(el, options) {
this.el = el;
const defaultOptions = {
onHover: (element, e) => {
console.log(':)))', element, e);
},
};
this.options = { ...defaultOptions, ...options };
this.mouseOverHandler = this.handleMouseOver.bind(this); // Vytvoření odkazu na metodu handleMouseOver
}
init() {
this.el.addEventListener('mouseover', this.mouseOverHandler); // Přidání posluchače události
}
destroy() {
this.el.removeEventListener('mouseover', this.mouseOverHandler); // Odstranění posluchače události
}
handleMouseOver(e) {
if (this.options.onHover) {
this.options.onHover(this.el, e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment