Javascript,如何在IE中检索文字对象的所有属性 [英] Javascript, how to retrieve ALL properties of a literal object in IE
问题描述
我有一个像这样的文字对象
i have a literal object like this
var O={
toString:function(){
// some code here
},
anotherMethod:function(){
// some code here
}
}
我通过for-in循环遍历对象
Im walk through object with for-in loop
for(var p in O){
// some stuff with p and O[p]
}
问题是toString属性将不会在IE浏览器中陷入循环!
The problem is toString property will not catch in the loop on IE browser!
推荐答案
阅读此页: ECMAScript DontEnum属性在Mozilla开发人员中心上.基本上,这是一个JScript错误.
Read this page: ECMAScript DontEnum attribute on Mozilla Developer Center. Basically, it's a JScript bug.
JScript将跳过其中的任何属性 具有相同名称的任何对象 对象原型中的属性 具有DontEnum属性的链. 如果具有DontEnum的属性 属性存在于原型中 链,或者实例属性为 标记为DontEnum,未枚举, 不管程序员定义了什么 该属性的值. JScript确实 不正确地检查DontEnum 属性.
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. If a property with the DontEnum attribute exists in the prototype chain, or if the instance property is marked DontEnum, it is not enumerated, regardless of programmer defined values for that property. JScript does not properly check the DontEnum attribute.
这篇关于Javascript,如何在IE中检索文字对象的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!