In javascript it\'s very popular for libraries/frameworks to let us define a callback function for post-processing of data.
eg.
load(\"5\", function(
Well, the load function could look like this:
function load(arg, callback) {
var element = { name: "foo " + arg }; // something to pass
if (typeof callback == 'function') {
callback(element);
}
}
With the typeof check we make sure that the callback argument is an object that we can invoke, a function.
Then your example:
load("5", function(element) {
alert(element.name); // Will show `"foo 5"`.
});