【发布时间】:2018-05-08 12:18:49
【问题描述】:
这里有两个简单的代码:
let myObject = {
objectName: () => {
console.log(this);
}
};
myObject.objectName();
第一个代码将“this”值打印为:{ }
let myObject = {
objectName: function() {
console.log(this);
}
};
myObject.objectName();
第二个代码将“this”值打印为:{ objectName: [Function: objectName] }
有人可以用简单的英语解释为什么箭头函数中的“this”具有不同的值吗? 谢谢!
【问题讨论】:
-
因为,好吧……here's some documentation
-
箭头函数采用其封闭范围的this。
标签: javascript this arrow-functions