DEV Community

Discussion on: How to optimize module encapsulation in Node.js

Collapse
 
cherif_b profile image
Cherif Bouchelaghem

In the Optimized encapsulation first example, for performance reasons, I guess functions could be defined outside the exported function and they still be available to use inside factory function.

// a-module.js

function privateFunction() {}

 function publicFunctionA() {}

 function publicFunctionB() {}


module.exports = function(sharedParameter) {

    return {

        publicFunctionA: publicFunctionA,
        publicFunctionB: publicFunctionB

    };

};

Great article BTW.