![](/img/trans.png)
[英]How define function in javascript in global context inside a function?
[英]`this` in global context and inside function
根据MDN的这个解释 :
this
指的是全局对象 然而,以下内容:
var globalThis = this;
function a() {
console.log(typeof this);
console.log(typeof globalThis);
console.log('is this the global object? '+(globalThis===this));
}
a();
...放在文件foo.js
产生:
$ nodejs foo.js
object
object
is this the global object? false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.