被替换的内置属性的IE8属性枚举(例如`toString`) [英] IE8 property enumeration of replaced built-in properties (e.g. `toString`)

查看:103
本文介绍了被替换的内置属性的IE8属性枚举(例如`toString`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常奇怪的问题,IE8的JS引擎(也可能是以前的版本,但是在IE8模式下不是IE9,因为JS引擎不会回退)。简化示例:

I've run into a very odd issue with IE8's JS engine (possibly previous versions as well, but NOT IE9 in IE8 mode since the JS engine doesn't fallback). Simplified example:

var foo = { toString : 42, x : 22 };
for(var n in foo){ 
    console.log(n)
}

// result: "x"

换句话说, toString 属性永远不会被枚举。也不会 valueOf hasOwnProperty 等...或 var x = 5; x.toFixed = 42;

In other words, the toString property never gets enumerated. Nor would valueOf, hasOwnProperty, etc... or var x = 5; x.toFixed = 42;

因此,即使您更换了本地存在的任何属性,也无法进行枚举。 ...

So any property that natively exists can not be enumerated as far as I can tell, even after you replace it...

我的问题 - 有没有人知道如何实际访问这些?!?我需要因为我正在走一个对象的原型而且 toString 函数没有被拾取。

My question -- Does anyone know of any way to actually access these?!? I need to because I'm walking the prototype of an object and the toString function isn't getting picked up.

推荐答案

因此,您在IE中遇到的行为是IE8及以下版本中所谓的JScript DontEnum Bug。

So, the behavior you're experiencing in IE is the so-called "JScript DontEnum Bug" which exists in IE8 and below.


在IE< 9,JScript将跳过对象原型链中具有DontEnum属性的同名属性的任何对象中的任何属性。

In IE < 9, JScript will skip over any property in any object where there is a same-named property in the object's prototype chain that has the DontEnum attribute.

来源: https://developer.mozilla.org/en/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug

这篇关于被替换的内置属性的IE8属性枚举(例如`toString`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆