Anonymous functions are
functions that are dynamically declared at runtime. They’re called anonymous
functions because they aren’t given a name in the same way as normal functions.
Anonymous
functions are declared using the function operator instead of the function declaration.
You can use the function operator to create a new function wherever it’s valid
to put an expression. For example you could declare a new function as a
parameter to a function call or to assign a property of another object.
Here’s
a typical example of a named function:
1.
function flyToTheMoon()
2.
{
3.
alert("Zoom!
Zoom! Zoom!");
4.
}
5.
flyToTheMoon();
Here’s
the same example created as an anonymous function:
1.
var flyToTheMoon = function()
2.
{
3.
alert("Zoom!
Zoom! Zoom!");
4.
}
5.
flyToTheMoon();