4 ms·
Yes, that's how you write a jQuery module. That's how I do it: (function($,undefined) { "use strict"; ... })(jQuery); Note the undefin
by panzi 13y ago
Yes, that's how you write a jQuery module. That's how I do it:
(function($,undefined) {
"use strict";
...
})(jQuery);
Note the undefined. That's because undefined is not a literal but a variable in JavaScript and can be assigned to anything. This way I ensure that undefined is really undefined and "x === undefined" works. But I digress.
- yuchi 13y agoAbout `undefined`, that’s not true anymore in ES5, btw.
- uxp 13y agoIt has nothing to do with jQuery, or anything else. (function() {})(); is a pretty standard Javascript pattern to execute an anonymous function immediately at evaluation. Because javascript has lexical scoping at the function, your use of "use strict"; and any var-prepended variables won't be hoisted up the prototype chain, potentially becoming globals. The ability to pass in a global as a local variable is simply a convenience. The global is available inside the closure anyways. It's a global after all. My point was, the battle over the dollar sign single character variable name is stupid.