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

