bind(), call(), and apply()
Why will this code fail to track clicks correctly?
const button = document.querySelector('button');
class Handler {
constructor() {
this.clicks = 0;
}
handleClick() {
this.clicks++;
console.log(this.clicks);
}
}
const handler = new Handler();
button.addEventListener('click', handler.handleClick);