JSFiddle - React, Tailwind, and code Playground
by Hoppertron
HTML
<div id="MainDiv">
</div>
JavaScript
var Item = function (prop1, prop2, prop3) {
this.prop1 = prop1,
this.prop2 = prop2,
this.prop3 = prop3,
this.prop4; //<----------------- Notice I'm not setting this yet.
}; // I'm setting it in MethodB.
// Is this stupid?
Item.prototype.MethodA = function() {
console.log("starting A")
this.MethodB(function () {this.MethodC}); //<-- Why doesn't MethodC run?
};
Item.prototype.MethodB = function(callback) {
console.log("starting B")
this.prop4 = "I'm prop 4";
console.dir(this);
callback();
};
Item.prototype.MethodC = function () {
console.log("starting C")
document.getElementById("MainDiv").innerHTML = this.prop4;
};
var MyItem = new Item("I'm prop 1","I'm prop 2","I'm prop 3");
try {
MyItem.MethodA(); //<-- Should call MethodA which calls MethodB which calls MethodC
}
catch(err) {
document.getElementById("MainDiv").innerHTML = err;
};