JSFiddle - React, Tailwind, and code Playground
HTML
<button id="myButton">Click</button>
JavaScript
function example1(){
this.state = {a: 1};
$('#myButton').on('click', function(){
// this will be the element myButton which has no state.
console.log(this.state); // undefined
});
}
function example2(){
this.state = {a: 1};
$('#myButton').on('click', (function(){
// since we binded this, it will log the state always no madder who the caller is.
console.log(this.state);
}).bind(this));
}
var ex1 = new example1();
var ex2 = new example2();