在node.js模塊和函數(shù)中“this”的含義我有一個(gè)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;是空對(duì)象,而this函數(shù)中的語句是node.js全局對(duì)象的陰影。我知道呀this關(guān)鍵字在功能上是不同的,但我不明白為什么首先this不等于全局和this在函數(shù)中等于全局。node.js如何注入global到this在函數(shù)作用域中,以及為什么不將其注入模塊作用域?
在node.js模塊和函數(shù)中“this”的含義
喵喔喔
2019-07-08 12:38:57