In plain JavaScript, consider the following: You want to have an object that has its own rendering method, and inside the rendering is a button that is to call another of the object’s functions.
As a basic example:
class Person () {
//...
incrementAge() { this.age++ }
render() {
return "<button onClick='this.incrementAge()'>Age += 1</button>"
}
}
Now, as you probably realize, this button will fail because this
refers to the click event now, and not the object itself.
Question
What’s the solution to making this button call the object’s function?