i am very new in jquery. so i was searching google for jquery callback function and i got a code but i did not understand the flow of the code. so please anyone help me to understand the coding flow.
here is the code
function mightyplugin(foo, callback){
// big code block here
callback.apply(this, [foo]);
}
mightyplugin("Bar!", function(param){
alert(param);
});
here i am passing "Bar!" as one argument to function mightyplugin and a anonymous function.
- what
callback.applydoes. whatthiskeyword will hold actually…. why it is required. - why
[foo]is passed as array. -
what would be the syntax if i pass many argument like
mightyplugin("Bar!","1stone","2ndone", function(param){ alert(param); });
i know callback function invoke when first function finish but here situation is different… why?
please explain…
thanks
First of all, this isn’t jquery. This is an example of how to deal with callback functions yourself, independent of jquery.
To answer your qestions:
applycan be found here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/applyapplyis an array of arguments.