Calling a javascript function (in the original function) from the called function?
Is there a way to call a function from within another function .. a bit tricky to explain. in the example. One function loads the html page, and when ready, it calls the original function.
I think I need to pass a link, but I don't know how ... if I set it to "this" - it doesn't seem to work
ANY ideas?
order.prototype.printMe = function(){
order_resume.loadthis("myTestPage.html", "showData");
}
order.prototype.testme= function(){
alert("i have been called");
}
//Then when in "loadthis" need to call
orderRsume.prototype.loadthis= function(){
// DO SOME STUFF AND WHEN LOADS IT ARRIVES IN OnReady
}
order.prototype.OnReady= function(){
/// NEED TO CALL ORIGINAL "testme" in other function
}
a source to share
It is not clear to me what you really want to do. In JS functions, first-class objects . This way, you can pass a function as a parameter to another function:
Cook("lobster",
"water",
function(x) { alert("pot " + x); });
order.somefunc = function(){
// do stuff
}
order.anotherone = function(func){
// do stuff and call function func
func();
}
order.anotherone(order.somefunc);
And if you need to reference an unnamed function from its body, the following syntax should work:
order.recursivefunc = function f(){
// you can use f only in this scope, afaik
f();
};
a source to share
I changed the signature of your loadthis function a bit when the order passed it to the actual load.
I also assumed that your doSomeStuff function accepts a callback function. I assumed it might be an AJAX call, so it would be trivial to call the callback at the end of the AJAX call. Please comment on this answer if you need more information on how to trigger this callback function from your AJAX call.
order.prototype.printMe = function(){
order_resume.load(this, "myTestPage.html", "showData");
}
order.prototype.testme= function(){
alert("i have been called");
}
//Then when in "loadthis" need to call
orderRsume.prototype.load = function(order, page, action){
// DO SOME STUFF AND WHEN LOADS IT ARRIVES IN OnReady
doSomeStuff(page, action, function()
{
order.OnReady();
});
}
order.prototype.OnReady= function(){
/// NEED TO CALL ORIGINAL "testme" in other function
this.testme();
}
a source to share