简体   繁体   中英

NodeJS Exporting module

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM