0

I see some iteration of ~~

;(function (window, Extensions, undefined){ --contents of a file-- });

Is there some pattern that calls the three variables of environment, wrapper, and error?

I don't understand this and would appreciate if anyone could enlighten me. I apologize for the brevity of the question. I don't completely know how to reference this.

epascarello
  • 185,306
  • 18
  • 175
  • 214
rememberlenny
  • 852
  • 2
  • 9
  • 19
  • It's *"self executing"*, nothing else ie executing it. The point of it is to execute immediately, creating a private scope within it that doesn't pollute the global namespace. – Kevin B May 01 '13 at 20:09
  • That function you posted isn't even self-executing. – Bergi May 01 '13 at 20:30

1 Answers1

2

The anonymous function is defined with three arguments, but usually only invoked with two parameters.

In the case of undefined, this ensures that the value is truly undefined, as in previous versions of JavaScript this kind of statement was legal: undefined = true;.

For the other parameters, this technique may be used to abbreviate long names (as in jQuery to $) or provide a way for code minification to shorten global variables (like window).

Rick Viscomi
  • 6,242
  • 2
  • 31
  • 46