Here's what I'm trying to do:
class foo{
constructor(){
this.num = 1;
}
log() {console.log(this.num)}
assign() {
document.querySelector('div').onclick = this.log
}
}
let bar = new foo();
bar.assign()
/* Click */ // goal: 1, actual: undefined
<div>Click Me</div>
When the class method runs, its scope is the HTML object itself, so this.num doesn't exist. How can I link the this of the callback to the class instance that set the listener, in this case bar