拿两个案例看下区别
案例一
var count = 12;
let show = {
count: 1,
fun: function () {
console.log(this) //show
console.log(this.count); //1
setTimeout(function () {
console.log(this) //window
console.log(this.count) //12
}, 1000)
}
}
show.fun()
案例二
{
let show = {
count: 1,
fun: function () {
console.log(this.count); //1
setTimeout(() => {
console.log(this) //{count: 1, fun: ƒ}
console.log(this.count) //1
}, 2000)
}
}
show.fun()
}