开发者

Why does 'this' in a function display window object where as 'this' in an argument displays the object from the function was invoked?

Why does 'this' in a function display window object where as 'this' in an argument displays 开发者_高级运维the object from the function was invoked?

function show(x){
 alert(x)//displays [object HTMLDivElement]
 alert(this)//displays [object Window]
}

<div onClick="show(this)">123</div>


Because the function is defined in the global scope, so "this" will refer to the window object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜