我正在尝试理解 ECMAScript 6 中的箭头函数。
这是我在阅读时遇到的定义:
箭头函数具有隐式
this
绑定,这意味着this
箭头函数内部的值与this
定义箭头函数的范围内的值完全一样!
根据定义,我认为this
anarrow function
应该包含与定义箭头函数相同的块级值。
代码:
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());