In trying to grasp some fundamentals of jQuery and JavaScript at the same time, I'm a little confused as to why jQuery takes an anonymous function as an argument. Like this:
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
as opposed to this:
$( "#target" ).click(alert("You clicked it."));
In jQuery's own "101" guide, they point out that "Passing functions as arguments is an extremely common idiom in jQuery." But they don't seem to explain why. Is it just to provide a wrapper for a block of expressions, or (I suspect) much more than that?