I was reading some posts about closures and saw this everywhere, but there is no clear explanation how it works - everytime I was just told to use it...:
//
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:
function flyToTheMoon() { alert("Zoom! Zoom! Zoom!"); } flyToTheMoon(); Here’s the same example created as an anonymous function:
var flyToTheMoon = function() { alert("Zoom! Zoom! Zoom!"); } flyToTheMoon();
For details please read here:
http://helephant.com/2008/08/23/javascript-anonymous-functions/