I have a class and in this class I have an event listener with a callback method.
In the callback method, this
will refer to the listener element.
How can i get this
refer to my class ?
class Myclass {
constructor() {
console.log(this); // Here this return Myclass
window.addEventListener('click', this.clickListener, false);
}
clickListener(e) {
console.log(this); // Here this return window
}
}
var myClass = new Myclass();