当使用require()加载模块时,module.exports和exports就指向了同一个空对象,但最终的结果始终以module.exports的指向为准。
①exports.username = 'victoria' module.exports = { name : 'vic', age : 20 }
var test = require('./test.js') console.log(test)
结果是:{name: 'vic', age: 20}
② module.exports.username ='vic' exports = { name : 'vc', age : 15 }
var test = require('./test.js') console.log(test)
结果是:{username : 'vic'}
③ module.exports.username ='vic' exports.age = 10
var test = require('./test.js') console.log(test)
结果是:{username : 'vic', age : 10}
④ exports = { name : 'vic' } module.exports = exports module.exports.age = 15
var test = require('./test.js') console.log(test)
结果是:{name : 'vic', age :15}