【发布时间】:2019-12-17 08:55:34
【问题描述】:
const profile = {
name: 'Alex',
getName :() =>{
return this.name;
}
};
在这里,我没有得到“亚历克斯”的名字。但是当我使用 function 关键字时,我得到了期望的结果。为什么?
【问题讨论】:
-
箭头函数在词法上绑定在一个对象字面量中,上下文是不是尚未创建的对象。
标签: object ecmascript-6 this arrow-functions