// this指向问题
var name = 'window'
var obj1 = {
name: 'obj1',
foo1: function () {
console.log(this.name)
return () => {
console.log(this.name)
}
},
foo2: () => {
console.log(this.name)
return function () {
console.log(this.name)
}
}
}
var obj2 = {
name: 'obj2'
}
// 写出以下执行结果
obj1.foo1.call(obj2)()//obj2 obj2
obj1.foo1().call(obj2)// obj1 obj1
obj1.foo2.call(obj2)()// window window
obj1.foo2().call(obj2)// window obj2
解释:https://blog.csdn.net/bbqq1314/article/details/105026430