JavaScript, jquery

returning data in callback function like as of jquery-ajax callback functions


<script>
var callback_tst = new function(){this.callback_tst = function(_data,{run,after_run}){

if(run != undefined){

run();

//if(typeof after_run == ‘function’){ // makes sure the send parameter is a function
// shortcut
if(after_run){

after_run(_data)

}
}else{

after_run(_data)
}
}
}

callback_tst.callback_tst(3,{

run:function()
{

console.log(‘running before function’);
},
after_run:function(data)
{
console.log(‘running the after function with tat param data : ‘+data);
}

});
</script>

This is just an sample test you can do more with it. For now i don’t have time to extend it, will be extending in free time.

Hope this is useful.
NIRAJ

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