I have been trying to understand anonymous functions. I have come to realise that adding extra parentheses at the end helps the anonymous functions execute. However, I have also come across code that seems to execute the anonymous function without the extra parentheses, and to my surprise I couldn't find the use of the jquery ready method either. It goes something like :-
$(function() {
$('#login_form #username').validator({
format: 'alphanumeric',
invalidEmpty: true,
correct: function() {
$('#login_form #username').text('Thanks');
},
error: function() {
$('#login_form #username').text('Plese fill username field');
}
});
});
The above file is simply included in an html file containing a form. I can't seem to understand how the above code is being executed automatically. Can somebody help shed some light on this ? Also, what difference would the extra parentheses make, such as :-
$(function() {
$('#login_form #username').validator({
format: 'alphanumeric',
invalidEmpty: true,
correct: function() {
$('#login_form #username').text('Thanks');
},
error: function() {
$('#login_form #username').text('Plese fill username field');
}
});
})();