JSFiddle - React, Tailwind, and code Playground
HTML
<button>hurray</button>
JavaScript
"this" in inner/nested functions (closures, callback functions)
var toto = {
myfun : function(){
function myInsideFun()
{
console.log(this);
}
console.log(this);
myInsideFun();
},
toString : function() {
return "toto";
}
};
//
var titi = {
cally : function(cb)
{
cb();
}
};
toto.myfun(); // toto Object, window
titi.cally(toto.myfun); // window, window
$("button").click (toto.myfun); // button Object, window