[英]Why does iterating over the properties of the window object causes an error in IE?
I experiences this problem very often and finally thought that it might be worth a question here. 我经常遇到这个问题,最后想到这里可能是一个问题。
Running the following code in IE, results in the output frameElement
, which means, that the property frameElement was found but if you try to access it via window["frameElement"]
it throws an error. 在IE中运行以下代码,将导致输出
frameElement
,这意味着找到了属性frameElement,但是如果尝试通过window["frameElement"]
访问它,则会引发错误。
for (var i in window){
try {
var c = window[i]
} catch(e) {
console.log(i);
}
}
I originally realized this problem when i tried to simply access every property of window, but always ended up with an error. 当我尝试简单地访问window的每个属性时,我最初意识到了这个问题,但总是以错误告终。
Does anyone know the reason for this? 有人知道原因吗? How can it be, that there is a property but that it is not accessible?
怎么可能有一个属性,但是它不可访问?
This can happen on any browser. 这可以在任何浏览器上发生。 Properties on any object, including Window, can be getters methods that can have side-effects including throwing exceptions.
任何对象(包括Window)上的属性都可以是吸气剂方法,这些方法可能具有副作用,包括抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.