What I mean is does node.js have object that are global function methods of. Like this in browser:
我的意思是节点。js的对象是全局函数方法。这样的浏览器:
function myGlobalFunction() {
console.log(this === window);
}
myGlobalFunction();
=> true
2 个解决方案
#1
28
The closest equivalent in node is global
. I'm not sure if it translates in all of the same ways, but if you open a REPL and type in this === global
, it will return true.
节点中最相似的是全局的。我不确定它是否以相同的方式转换,但是如果您打开一个REPL并在=== = global中输入,它将返回true。
Here's a discussion on the global object, though some it the information may be deprecated as it's pretty old: 'Global' object in node.js
这里有一个关于全局对象的讨论,尽管有些信息可能已经过时了:node.js中的“global”对象
#2
14
Yes, the global
variable is the global object in Node.js
是的,全局变量是Node.js中的全局对象
From the docs:
从文档:
global# {Object} The global namespace object. In browsers, the top-level scope is the global scope. That means that in browsers if you're in the global scope var something will define a global variable. In Node this is different. The top-level scope is not the global scope; var something inside a Node module will be local to that module.
全局#{对象}全局命名空间对象。在浏览器中,*范围是全局范围。这意味着,在浏览器中,如果你在全局范围var中,某些东西会定义一个全局变量。在Node,这是不同的。*范围不是全局范围;节点模块中的某个变量将是该模块的本地变量。
#1
28
The closest equivalent in node is global
. I'm not sure if it translates in all of the same ways, but if you open a REPL and type in this === global
, it will return true.
节点中最相似的是全局的。我不确定它是否以相同的方式转换,但是如果您打开一个REPL并在=== = global中输入,它将返回true。
Here's a discussion on the global object, though some it the information may be deprecated as it's pretty old: 'Global' object in node.js
这里有一个关于全局对象的讨论,尽管有些信息可能已经过时了:node.js中的“global”对象
#2
14
Yes, the global
variable is the global object in Node.js
是的,全局变量是Node.js中的全局对象
From the docs:
从文档:
global# {Object} The global namespace object. In browsers, the top-level scope is the global scope. That means that in browsers if you're in the global scope var something will define a global variable. In Node this is different. The top-level scope is not the global scope; var something inside a Node module will be local to that module.
全局#{对象}全局命名空间对象。在浏览器中,*范围是全局范围。这意味着,在浏览器中,如果你在全局范围var中,某些东西会定义一个全局变量。在Node,这是不同的。*范围不是全局范围;节点模块中的某个变量将是该模块的本地变量。