Reputation: 1338
Now a days it's some what customary to use the modular pattern when writing javascript on the web. But it's rarely that I see this approach when looking at nodejs modules distributed on npm. Is there way that nodejs differs from the javascript implementations on the web that makes the use of the modular pattern redundant?
Upvotes: 1
Views: 67
Reputation: 3144
Because there's no good reason to. The reason wrapping your code in (function () {
and })();
is useful is that browser JavaScript executes on a global scope. Node.js, on the other hand, "sandboxes" code to it's own file and only shares code via the module.export
system. (you can also modify a globals
object, but you're evil if you do)
Upvotes: 1