So the have seem something like this today:
$$('input').each(function() {
// do something
});
What is the difference between that and this:
$$('input').each( // do something );
The private function on the first example is within that for loop scope, so it is not reference-able anywhere else, so what would the benefit of having it?
The anonymous function knows its current scope and variables.
This function would alert ‘test’ because
foois defined within its scope.This function would cause a javascript error stating that the variable
foois undefined.If you need to define a function that only makes sense within an exact scope and don’t want to throw lots of variables around or recalculate a lot of things, it’s more comfortable to define an anonymous function.