Functions in JavaScript can be passed as values to other functions and executed. E.g.:
function execute(fn)
{
fn(); // execute function passed as a parameter
}
var alertHelloWorld = function ()
{
alert("Hello World");
};
execute(alertHelloWorld); // this will alert "Hello World"
So what the jQuery Autocomplete plug-in is doing, is caching whatever functions are passed in it's initializer, and then executing them when it needs to. I.E.: when data needs to be handled or when data has been handled.
Here's an example, somewhat similar to the Autocomplete plug-in:
// execute three functions contained in an object literal
function execute(o)
{
o.One();
o.Two();
o.Three();
};
// call "execute" passing in object literal containing three anonymous functions
// this will alert "One", then "Two", then "Three"
execute(
{
One: function () { alert("One"); },
Two: function () { alert("Two"); },
Three: function () { alert("Three"); }
});
Parameters can also be passed from a function that is executing another function:
function execute(fn)
{
// execute function passed as a parameter with a parameter
fn("Hello World");
};
execute(function (s)
{
// parameter "s" supplied by "execute" will contain "Hello World"
alert(s);
});