let f3= ()=>console.log(this)
let o1 ={
f3,
test(){
f3 = ()=>console.log('hh')
f3()
}
}
o1.test();
f3();
o1.f3();
先这么理解 把 f3 改成 f3:f3 可能就很简单的理解了
let f3= ()=>console.log(this)
let o1 ={
f3:f3,// 这里的f3 = ()=>console.log(this) 所以后面调用的时候是 取得windows
test(){
f3 = ()=>console.log('hh')
f3()
}
}
// 去执行test函数 全局 f3 变成了 ()=>console.log('hh') test内的 f3 调用的是全局 f3 所以输出 hh
o1.test();
// 调用f3 全局 f3 变成了 ()=>console.log('hh') 所以输出 hh
f3();
// 在一开始声明对象的时候 let o1 ={f3, 简写 f3:f3 在一开始没有改变的时候赋值,
// 所以他是 this 因为是箭头函数,没有this也不会指向对象 所以指向windows
o1.f3();