考虑以下顶级JavaScript代码:
if (this.window === window)
alert('same');
else
alert('different'); // alerts: different
Run Code Online (Sandbox Code Playgroud)
为什么this.window和window不完全相同?我也在表达式的rhs上尝试了'this'并得到了相同的结果.
在Internet Explorer中(我测试的是8.0.7600),this没有限定符实际解析为全局窗口对象.在我所尝试过的所有其他浏览器中(Chrome,Firefox,Opera),this.window === window在这种情况下也是如此 - 并且this === window也是有帮助的.
在IE中试试这个来验证:
if (this === window)
alert('same');
else
alert('different');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6168 次 |
| 最近记录: |