Wednesday, 5 April 2017

Why encapsulate module in function? [duplicate]

This question already has an answer here:

So I'm reading some node.js-modules in a school example app, and they are all instantiated in a function like this:

(function() {
    "use strict";

    // Some declarations

    module.exports = some value;
}());

That is, they are all encapsulated by an anonymous function like this:

(function() {
    // Module
}());

Does anyone know what the purpose may be for doing so? Has it something to do with efficiency?



via Jesper

No comments:

Post a Comment