How does anonymous function know what parameters are being passed in? For example,
Case 1:
$( "li" ).each(function( index ) {
console.log( index + ": " + $( this ).text() );
});
Case 2:
$( "li" ).each(function(e) {
e.preventDefault();
});
Case 3:
$( "li" ).each(function( index, element ) {
console.log( index + ": " + element + $( this ).text() );
});
In each of these cases, how does the anonymous function know what e, index, element are?
.eachpasses those values to the function. Also note that your second example doesn't work, because.eachdoesn't pass an event object to the callback. And you can name the parameters however you want to..eachpasses the values you specify to the anonymous function.