代码语言:javascript复制
function Person () {
this.name = 'little bear',
this.age = 18
setTimeout(()=>{
console.log(this
)
})
}
var a = new Person()
setTimeout里的this代表new Person出来的对象
代码语言:javascript复制function Person () {
this.name = 'little bear',
this.age = 18
setTimeout(function(){
console.log(this
)
})
}
var a = new Person()
setTimeout里的this代表window
由于箭头函数不改变this,所以setTimeout里面的箭头函数this,不能改变