JavaScript解析函数中怎么使用this
函数中使用 this(默认)
在函数中,函数的所属者默认绑定到 this 上。
在浏览器中,window 就是该全局对象为 [object Window]:
实例
function myFunction() {
return this;
}
函数中使用 this(严格模式)
严格模式下函数是没有绑定到 this 上,这时候 this 是 undefined。
实例
"use strict";
function myFunction() {
return this;
}
事件中的 this
在 HTML 事件句柄中,this 指向了接收事件的 HTML 元素:
实例
<button onclick="this.style.display='none'">
点我后我就消失了
</button>
本文标题:JavaScript解析函数中怎么使用this
本文链接:https://www.qqooo.cn/post/6458.html
版权说明:网站文章均来源于手工整理和网友投稿,若有不妥之处请来信 xsds@vip.qq.com 处理,谢谢!