参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/globalThis
全局属性 globalThis
包含全局的 this
值,类似于全局对象(global object)。
例子:
const log = console.log;
function canMakeHTTPRequest() {
return globalThis;
}
console.log(canMakeHTTPRequest());
// expected output (in a browser): true
var aahello = "yyyy"
bbb = "youfwkfew"; //属于globalThis
function call() {
cc = "jflkdskfjdlsk";
return cc;
}
call(); //执行后cc属于globalThis
log(canMakeHTTPRequest());
结果:
$ node for.js
Object [global] {
global: [Circular],
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTim