JOAOSANTACRUZ.COM

Callback function

A simple example on "How to use Javascript callback functions"

# This is the main function - - - - -
function functionA(name, fn_end){


    var output = {id:2, title:'The empire of the ' + name };


    fn_end(output);


}



# This function will be called just after "functionA" ends - - - -
var functionB = function(output){ alert("Result is: \n" + output.title); }

 

# This is just a simple var that will be passed as a parameter - - - -
var name = "SUN";

var result = functionA (name, functionB);

Go Back