简体   繁体   English

为什么迭代窗口对象的属性会导致IE错误?

[英]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);
    }
}

FIDDLE 小提琴

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.

相关问题 迭代 window 对象的属性时出现异常“组件不可用” - Exception “Component is not available” when iterating over window object's properties 使用数组遍历对象属性 - Iterating over object properties with arrays JavaScript 迭代对象属性和原型链 - JavaScript iterating over object properties and the prototype chain 由转发器量角器迭代对象属性 - Protractor by repeater Iterating over object properties 在脚本中迭代 object 的属性# - Iterating over properties of an object in Script# 在每次迭代中延迟地迭代对象属性 - Iterating over object properties with delay in each iteration 在 object 上循环/映射/迭代导致无法读取未定义的属性(读取“映射”)错误,但存在数据 - Looping/Map/Iterating over object results in Cannot read properties of undefined (reading 'map') error, but data is present JavaScript遍历对象属性-卡在循环引用循环中 - JavaScript Iterating over object properties - Stuck in circular reference loop 在递归循环中迭代和处理JSON对象会导致堆栈超出错误 - Iterating and processing JSON Object in recursive loop causes Stack Exceeded Error 迭代对象属性 - iterating an object properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM