第一个比较好理解,箭头函数的this用法,在定义时绑定的,所以应该是输出21,foo.call(...)再去绑定无效
this.id = 21;
var foo= ()=>{console.log(this.id)};
this.foo.call({ id: 42 });
但是第二个为什么绑定有效,这个没理解
this.id3 = 21;
function foo3() {
var f=() => { console.log('id3:', this.id3); };
f();
}
foo3.call({ id3: 42 });
绑定的不是
f
的 this ,而是foo3
的。f
用的是foo3
的 this 。