Javascript Magic

Could you ever think of passing a function inside a function as a parameter and excute it inside the called function just as any other. It can be done by the way of javascript in the most simplistic of the manners without having to bring in a concept of pointers or references paradigm.
Taste this:

function Cook( i1, i2, f )
alert("get the " + i1);
function show(){
Cook( "lobster","water",function(x) { alert("pot " + x); } );
Cook( "chicken","coconut",function(x) { alert("boom " + x); } );

Call the function show() on bodyload in a page and watch the magic!! For more magic read the entire article


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: