klewis
klewis

Reputation: 8379

Various openings to creating the revealing module pattern

When we initiate a plan to build a revealing module pattern, what is the biggest difference between constructing the pattern to start this way...

var MODULE = function() {}();

and constructing the pattern to go this way...

var MODULE = (function() {})();

Benefits? Purpose?

Also as an additional question, will either of these techniques allow jQuery to process without passing the $ into them?

Thanks for any feedback!

Upvotes: 1

Views: 85

Answers (1)

Waxen
Waxen

Reputation: 1782

There's a jsHint option to warn when functions aren't wrapped in parens. The description of the option reads as follows:

"This option prohibits the use of immediate function invocations without wrapping them in parentheses. Wrapping parentheses assists readers of your code in understanding that the expression is the result of a function, and not the function itself."

As for your question about jQuery; Yes, jQuery will be available, provided you've included it, obviously. Having said that, I would still recommend passing '$' or 'jQuery' as a parameter to your function. If you don't, every time you reference it, the engine will have to go up to the parent scope to find it. Not a huge deal, but less efficient, especially if you make heavy use of jQuery. If you pass it in, then jQuery is defined in your function's scope, and won't need to go searching in ancestral scopes for it.

Upvotes: 2

Related Questions