简体   繁体   English

NodeJS导出模块

[英]NodeJS Exporting module

Browsing through existing modules in the NPM repository, I've seen modules that uses: 浏览NPM存储库中的现有模块,我看到使用的模块:

    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? 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. 严肃对待这一因素的两种方法之间没有明显的性能差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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