<分区>
我正在尝试理解 ECMAScript 6 中的箭头函数。
这是我在阅读时遇到的定义:
Arrow functions have implicit
this
binding, which means that the value of thethis
value inside of an arrow function is aways the same as the value ofthis
in the scope in which the arrow function is defined!
根据定义,我认为 arrow function
的 this
应该包含与箭头函数定义相同的 block 级值。
代码:
var test = {
id: "123123",
k: {
laptop: "ramen",
testfunc: () => console.log(this)
}
}
console.log(test.k.testfunc);
但是,我从代码中得到了这个结果
function testfunc() {
return console.log(undefined);
}
我认为我会得到的输出是:
{"laptop": "ramen"}
如果我运行这个
console.log(test.k.testfunc());