What does this mean when a function ends with}) (jQuery) ;?

I tried googleing but Google doesn't seem to care about parentheses ...

+5
source share
3 answers

If you see this:

(function($) {
    // ...code using $...
})(jQuery);

This does two things:

  • Defining an anonymous function using $jQuery as a reference.
  • A call going through jQuery.

You can do it as follows:

function foo($) {
    // ...code using $...
}
foo(jQuery);

... but this creates an unnecessary character.

, jQuery jQuery $, jQuery.noConflict() jQuery $ , jQuery, (Prototype MooTools, ) $, - jQuery . $ , , .

+3

/- jQuery .

, functionCall(jQuery) , /.

+1

...

(function($) {
    // do something with $
})(jQuery);

, - jQuery ( function(a) {...}, jQuery a), $ jQuery .

, $(this) .., jQuery (, , $ jQuery ).

+1

All Articles