Reputation: 415
Browsing through existing modules in the NPM repository, I've seen modules that uses:
module.exports = (function(){
return {
// objects from the module
};
})();
And modules that uses
module.exports = { //objects };
Is there any performance difference from them? Is there a third option/pattern for module organization in Node?
Thanks!
Upvotes: 1
Views: 172
Reputation: 2099
The 1st approach with anonymous function is used to avoid potential name conflicts. That is the only reason for doing that. There will be no noticeable performance difference between two approaches to take this factor seriously.
Upvotes: 3