this Keyword in Different Contexts
How can you fix the 'this' binding in this code?
class Button {
constructor(text) {
this.text = text;
this.clicked = false;
}
click() {
this.clicked = true;
console.log(`${this.text} clicked`);
}
}
const button = new Button('Submit');
const onClick = button.click;
onClick();