关于各种函数的 this 指向问题

普通函数: this指向 window

function() {

console.log(this)

}

自调用函数:this 指向 window

(function(){

console.log(this)

})()

构造函数调用: this指向实例对象,原型对象指向的也是实例对象

var o {

saih: function() {

console.log(this)

}

}

时间绑定函数:this 指向绑定事件

var but = document.querySelector("button");

but.onclick = function() {

console.log(this)

}

 

posted @ 2020-10-15 14:48  前端--张帅  阅读(119)  评论(0)    收藏  举报