Saturday, 15 January 2011

javascript - Properties with 'enumerable' flag are listed in for/in loop? -



javascript - Properties with 'enumerable' flag are listed in for/in loop? -

i new javascript , learning now. have below query regarding for/in loop , 'enumerable' attribute of javascript object property.

consider next code snippet:

var base of operations = {x:1, y:2, z:3} var derived = object.create(base) derived["a"]=4 for(var prp in derived) { console.log(prp, derived.propertyisenumerable(prp)) }

for above code output is:

a true x false y false z false

as understand inherited properties not enumerable, , question why listed in for/in loop .

as per understanding output should :

a true.

please right me if wrong?

from mdn:

every object has propertyisenumerable method. method can determine whether specified property in object can enumerated for...in loop, with exception of properties inherited through prototype chain.

for..in iterate through of object's enumerable properties, propertyisenumerable true object's "own" enumerable properties, , false inherited ones.

javascript

No comments:

Post a Comment