0

Could someone explain in layman's terms what the following construct is doing:

(function(jQuery) {
   // some javascript code here
})(jQuery);

of course, any "read this post", or "read this link", or even "don't do that! this is a better way" kind of responses are also more than welcome.

SRy
  • 2,743
  • 7
  • 33
  • 54
user1003295
  • 61
  • 1
  • 4

1 Answers1

0

This code is creating an anonymous, self-invoking function with a reference to a variable called jQuery from the parent scope passed as first argument.

This syntax is often use to "namespace" the code you are writing to avoid the pollution of the global scope, very popular with JavaScript Module pattern.

rochal
  • 7,243
  • 2
  • 30
  • 53