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