JSFiddle - React, Tailwind, and code Playground
HTML
<a href="javascript:void(0);" id="second">Invoke mySecondFunction</a><br />
<a href="javascript:void(0);" id="third">Invoke myThirdFunction</a>
JavaScript
var myNameSpace = {
myFirstFunction: function(){
alert("Hello World!");
},
mySecondFunction: function(){
this.myFirstFunction();
},
myThirdFunction: function() {
return (function() {
// this call will fail b/c the containing closure changes the 'this' reference
this.myFirstFunction();
})();
}
};
$("#second").click(function() { myNameSpace.mySecondFunction(); });
$("#third").click(function() {
try {
myNameSpace.myThirdFunction();
}
catch (er) {
alert("Error thrown because \"this\" doesn't reference myNameSpace inside a closure.");
}
});