Possible Duplicate:
What are the benefits to using anonymous functions instead of named functions for callbacks and paramaters in JavaScript event code?
I've been reading/writing some basic Javascript and JQuery code and noticed that in almost every tutorial that I read, anonymous functions are used instead of named functions.
For example, something like:
$('document').ready(function(){
alert("I am ready.");
});
versus:
function ready(){
alert("I am ready.");
}
$('document').ready(ready());
Isn't the second example, easier to read/understand? Now, I realize that these are very simple examples but the point I'm trying to get at is that I feel that anonymous functions make the code look cluttered and hard to understand. There are braces and parentheses everywhere and you can't use that function anywhere else since it's anonymous.
Isn't the whole point of functions to be able to organize your code into distinct modules to make your code look cleaner, to make debugging easier and to avoid redundant code?
Why would anyone use anonymous functions over named functions? What purpose do they serve?