I want to make a .on function but I'm having a problem. The below code calls the .on function but to do the alert, the variable ready has to be true. I don't want to call the .on function after the "ready = true". I hope you understand me. Thanks.
var test = {};
var ready = false;
test.on = function(argument, callback) {
if (typeof argument !== "string" || "function" !== typeof callback) return;
if (typeof callback === "function") {
if (argument === "hi" && ready) {
callback("hi");
}
}
}
test.on("hi", function(a) {
alert(a);
});
ready = true; // Now it should evaluate the above function