module.exports vs exports in Node.js

前端 未结 23 1277
自闭症患者
自闭症患者 2020-11-22 06:11

I\'ve found the following contract in a Node.js module:

module.exports = exports = nano = function database_module(cfg) {...}

I wonder what

23条回答
  •  悲哀的现实
    2020-11-22 07:08

    var a = {},md={};
    

    //Firstly,the exports and module.exports point the same empty Object

    exp = a;//exports =a;
    md.exp = a;//module.exports = a;
    
    exp.attr = "change";
    
    console.log(md.exp);//{attr:"change"}
    

    //If you point exp to other object instead of point it's property to other object. The md.exp will be empty Object {}

    var a ={},md={};
    exp =a;
    md.exp =a;
    
    exp = function(){ console.log('Do nothing...'); };
    
    console.log(md.exp); //{}
    

提交回复
热议问题