0


what is the difference b/w

$(function(){

});

and

(function ($) {
//found this code in jquery uobtrusive ajax
}(JQuery));

first code snippet is simply shorthand for document ready. i have no idea about second code snippet: what does it do and how does it differ from the first code snippet.

Muhammad Adeel Zahid
  • 17,474
  • 14
  • 90
  • 155

1 Answers1

4

The second snippet creates an anonymous function and executes it immediately, without waiting for anything to load.

It's used to create a local variable (parameter) named $ that refers to jQuery, even if someone calls jQuery.noConflict().

It also hides internal variables created in the function from the global scope.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • how can i change values of some variables inside this anonymous function plz see this question http://stackoverflow.com/questions/6135029/context-is-missing-when-using-unobtrusive-ajax-in-asp-net-mvc-3 – Muhammad Adeel Zahid May 31 '11 at 16:23