nodejs有本身的模块系统,分为文件模块和内置模块。webpack是运行在node环境中,在学习vue-cli的webpack配置的时候,vue
exports.fun1=function(param){ // } node
exports.fun2=function(param){ // },webpack
好比utils.js文件。。。web
module.exports = { // }vue-cli
他们有什么区别呢?我只是本身的理解与资料总结,会一直更新与更改:学习
js
文件一建立,都有一个var exports = module.exports = {};
,使exports
和module.exports
都指向一个空对象。module
是全局内置对象,exports
是被var
建立的局部对象。module.exports
和exports
所指向的内存地址相同module.exports
像是exports
的大哥,当module.exports
以{}
总体导出时会覆盖exports
的属性和方法,module.exports.
/exports.
上时,exports.id=1
和module.exports.id=100
,module.exports.id=function(){}
和exports.id=function(){}
,最后id的值取决于exports.id
和module.exports.id
的顺序,谁在后,就是最后的值exports
和module.exports
同时赋值时,exports
所使用的属性和方法必须出如今module.exports
,若属性没有在module.exports
中定义的话,出现undefined
,若方法没有在module.exports
中定义,会抛出TypeError
错误。RHS查询总之:若是只是单一属性或方法的话,就使用exports.属性/方法
。要是导出多个属性或方法或使用对象构造方法
,结合prototype
等,就建议使用module.exports = {}
。prototype