在node.js模塊和函數中“this”的含義我有一個JavaScript文件,它由require.// loaded by require()var a = this; // "this" is an empty objectthis.anObject = {name:"An object"};var aFunction = function() {
var innerThis = this; // "this" is node global object};aFunction();(function(anyParameter){
console.log(anyParameter.anObject);})(
this // "this" is same having anObject. Not "global");我的問題是:this無功a = this;是空對象,而this函數中的語句是node.js全局對象的陰影。我知道呀this關鍵字在功能上是不同的,但我不明白為什么首先this不等于全局和this在函數中等于全局。node.js如何注入global到this在函數作用域中,以及為什么不將其注入模塊作用域?
在node.js模塊和函數中“this”的含義
喵喔喔
2019-07-08 12:38:57