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);
f(i1);
f(i2);
}
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 http://www.joelonsoftware.com/items/2006/08/01.html

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: