NodeJS“这个"空对象

编程入门 行业动态 更新时间:2024-10-27 23:25:02
本文介绍了NodeJS“这个"空对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

为什么 NodeJS 中的this"是一个空对象?module.exports"属于哪里?

Why is the "this" an empty object in NodeJS? Where does the "module.exports" belongs to?

我认为 "module.exports..." 可以写成 "this.module.exports..." 但它不起作用.

I thought that "module.exports..." could be written as "this.module.exports..." but it won't work.

谢谢

推荐答案

如果您在实际模块中:

module 是对当前模块的引用

exports 是对导出数据的引用.它被 NodeJS 缓存起来并传递给需要

exports is a reference to the exported data. It gets cached away by NodeJS and delivered to other modules that require it

this 是对 exports 对象的替代引用

this is an alternate reference to the exports object

module.exports 是对 exports 对象的替代引用

module.exports is an alternate reference to the exports object

this.moduleundefined

this 是空的,因为如上所述,它是对与 exports 相同的对象的引用,该对象将由开发人员填充.

this is empty because as noted above it is a reference to the same object as exports, which is to be populated by the developer.

如果this.module 是对module 的引用,那么由于this 是对exports 的引用,它会将 module 本身与其他导出的项目一起导出.我怀疑这是需要的.

If this.module was a reference to module, then since this is a reference to exports, it would export the module itself along with the other exported items. I doubt this would be desired.

如果您在 REPL 中,则定义了 this.module.

If you are in the REPL, then this.module is defined.

这篇关于NodeJS“这个"空对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 16:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1397129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   NodeJS   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!