栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

vars存储在Node.js中的什么位置?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

vars存储在Node.js中的什么位置?

因此,每个节点模块都包装为函数的主体,如节点源代码中所示

NativeModule.wrapper = [  '(function (exports, require, module, __filename, __dirname) { ',  'n});'];

因此,如果您使用声明了一个变量

var
,则该变量对于模块而言是函数局部的,基本上是该模块的私有变量。这是不是一个性质
global
module
module.exports
,或
this
。如果您忘记了
var
,它将
global
作为属性进入对象。如果在上显式创建一个属性
this
,则该属性将进入
exports
其他模块并可供其他模块使用。

这是一个希望能启发您的小程序。

var aDeclaredVar = '*aDeclaredVar*';undeclaredVar = '*undeclaredVar*';this.aThisProperty = '*aThisProperty*';module.aModuleProperty = '*aModuleProperty*';module.exports.anExportProperty = '*anExportProperty*';console.log('this', this);console.log('this === exports', this === exports);console.log('this === module', this === module);console.log('this === module.exports', this === module.exports);console.log('aDeclaredVar', aDeclaredVar);console.log('undeclaredVar', undeclaredVar);console.log('this.aThisProperty', this.aThisProperty);console.log('module.aModuleProperty', module.aModuleProperty);console.log('module.exports.anExportProperty', module.exports.anExportProperty);console.log('global.undeclaredVar', global.undeclaredVar);console.log('global.aDeclaredVar', global.aDeclaredVar);

它的输出是:

this { aThisProperty: '*aThisProperty*',  anExportProperty: '*anExportProperty*' }this === exports truethis === module falsethis === module.exports trueaDeclaredVar *aDeclaredVar*undeclaredVar *undeclaredVar*this.aThisProperty *aThisProperty*module.aModuleProperty *aModuleProperty*module.exports.anExportProperty *anExportProperty*global.undeclaredVar *undeclaredVar*global.aDeclaredVar undefined


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/436663.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号