【发布时间】:2016-07-08 17:25:57
【问题描述】:
var obj = {
name: 'hello',
getName: function(){
return () => {return this.name; }
}
}
var name = 'world';
var nameFunc = obj.getName();
console.log(nameFunc())
结果是“hello”,而不是“world”。 我有点困惑。
【问题讨论】:
-
你会得到
"world"和(0,obj.getName)()()。
标签: javascript object scope global arrow-functions