views:

123

answers:

1

Hi, i have a literal object like this

var O={

 toString:function(){
  // some code here
 },
 anotherMethod:function(){
  // some code here
 }

}

Im walk through object with for-in loop

for(var p in O){
 // some stuff with p and O[p]
}

The problem is toString property will not catch in the loop on IE browser!

+2  A: 

Read this page: ECMAScript DontEnum attribute on Mozilla Developer Center. Basically, it's a JScript bug.

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.

Ionuț G. Stan