本文介绍了JavaScript this.window不等于window的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下顶级JavaScript代码:
Consider the following top-level javascript code:
if (this.window === window)
alert('same');
else
alert('different'); // alerts: different
为什么this.window和窗口不严格相等?我还在表达式的rhs上尝试了'this'并得到了相同的结果。
Why is this.window and window not strictly equal? I've also tried 'this' on the rhs of the expression and get the same result.
推荐答案
在Internet Explorer中(8.0) .7600是我测试的),这个
没有限定符实际上解析为全局窗口对象。在我尝试过的所有其他浏览器中(Chrome,Firefox,Opera), this.window === window
在该上下文中 - 并且,有用的是,这个===窗口
以及。
In Internet Explorer (8.0.7600 is what I've tested), this
with no qualifier actually resolves to the global window object. In all other browsers I've tried (Chrome, Firefox, Opera), this.window === window
in that context - and, helpfully, this === window
as well.
在IE中尝试验证:
if (this === window)
alert('same');
else
alert('different');
这篇关于JavaScript this.window不等于window的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!