2020.11.23

单独使用this

单独使用 this,则它指向全局(Global)对象。

在浏览器中,window 就是该全局对象为 [object Window]:

var x = this;
 
函数中使用this:
function myFunction() {
return this;
}
事件中的this

在 HTML 事件句柄中,this 指向了接收事件的 HTML 元素:

<button onclick="this.style.display='none'">
点击这里
</button>
对象方法中绑定:
var person = {
firstName : "John",
lastName : "Doe",
id : 5566, myFunction : function() {
return this;
}
};
posted @ 2020-12-23 17:21  鯨落  阅读(64)  评论(0编辑  收藏  举报