深入理解node exports和module.exports區(qū)別
我們只需知道三點即可知道 exports 和 module.exports 的區(qū)別了:
1.exports 是指向的 module.exports 的引用
2.module.exports 初始值為一個空對象 {},所以 exports 初始值也是 {}
3.require() 返回的是 module.exports 而不是 exports
所以:
• 我們通過
var name ='nswbmw';
exports.name = name;
exports.sayName =function(){
console.log(name);
}
給 exports 賦值其實是給 module.exports 這個空對象添加了兩個屬性而已,上面的代碼相當于:
var name ='nswbmw';
module.exports.name = name;
module.exports.sayName =function(){
console.log(name);
}
以上這篇深入理解node exports和module.exports區(qū)別就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
- Node.js學習教程之Module模塊
- vue中node_modules中第三方模塊的修改使用詳解
- 深入理解Node module模塊
- nodejs中exports與module.exports的區(qū)別詳細介紹
- node.js中module.exports與exports用法上的區(qū)別
- NodeJS學習筆記之Module的簡介
- node中modules.exports與exports導出的區(qū)別
- 詳解Node.js中exports和module.exports的區(qū)別
- Node.js 中exports 和 module.exports 的區(qū)別
- 淺談node中的exports與module.exports的關系
- node.js中module模塊的功能理解與用法實例分析
相關文章
Angular2.0實現(xiàn)modal對話框的方法示例
這篇文章主要介紹了Angular2.0實現(xiàn)modal對話框的方法,結合實例形式分析了angular2.0實現(xiàn)modal對話框的樣式、界面及功能等相關操作技巧,需要的朋友可以參考下2018-02-02
淺談angularjs $http提交數(shù)據(jù)探索
這篇文章主要介紹了淺談angularjs $http提交數(shù)據(jù)探索,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01
angular2 ng2-file-upload上傳示例代碼
這篇文章主要介紹了angular2 ng2-file-upload上傳示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08

