标签:
        var module.exports = {};
        var exports = module.exports;
        在模块内,没对module.exports和exports做任何更改前,他们都是指向同一个空对象。
        exports = function(){};
        //在其他模块内
        require(...);//得到{}
        此时在其他模块内使用require引用上面模块导出的对象时,发现为空对象,为什么?因为使用exports=function(){}时,是将exports的引用指向了这个函数,而module.exports的引用还是空对象,并且其       他模块使用require引用的是module.exports,所以此处会得到空对象,而不是函数。当然此处写成module.exports = function(){}肯定是没问题的。
             exports.a = 123;
             exports.b = 456;
        exports = function fn(){}; // outputs "@routes {}"
        exports.fn = function fn(){};  // outputs "@routes { fn: [Function: fn] }"
        module.exports = function fn(){};  // outputs "@routes function fn(){}"
        module.exports.fn = function fn(){};  // outputs "@routes { fn: [Function: fn] }"
标签:
原文地址:http://www.cnblogs.com/yuyuj/p/4559094.html