什么是“这个”在nodejs模块中意味着什么? [英] What does "this" mean in a nodejs module?

查看:163
本文介绍了什么是“这个”在nodejs模块中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的代码,如下所示,并将其作为节点模块执行:

I have a simple codes like the following and execute it as a node module:

console.log(this);
module.exports = {…};

我知道 global 是默认的上下文(比如窗口在浏览器中),但这个关键字是指什么?

I know that global is the default context (like window in browsers), but what does the this keyword refer to?

推荐答案

(在模块的上下文中)与导出相同node.js中的。但是,您通常应该使用 exports / module.exports ,以便明确清楚您要修改的内容。

this (in the context of a module) is the same as exports in node.js. However you should generally use exports/module.exports instead, so that it's explicitly clear what you're modifying.

这篇关于什么是“这个”在nodejs模块中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆