I’m wondering about the following.
Giving this Code:
function displayprops(obj, name) {
console.log(name+":");
for(var prop in obj)
console.log(prop + ": " + obj[prop]);
}
var first = {prop: {}};
displayprops(first, "first"); // "prop: [object Object]"
var second = Object.create(first);
Object.defineProperty(second,"prop",{
enumerable:false
});
displayprops(second, "second"); // "prop: undefined"
All Objects created from first should Obviously onherit the
prop property.
But Why does an Object created from second still shows the prop in his properties when iterating over it, note that its value is undefined.
I expected when setting the enumerable descriptor to false, the Objects which inherit from this prototype, shouldn’t show those properties any more
Edit:
When i extend Object.prototype (for whatever reason) with a method
and setting the methods enumerable descriptor to false
it behaves as expected
Could someone explain this, maybe im thinkin in the wrong direction
Thx for the answers =)
This is a bug in the V8 JavaScript engine. I’ve come across it before. Enumerable properties in the prototype chain are included even if shadowed by a non-enumerable property.
There’s already a bug report for it.
If I can find it again, I’ll post it here.Here it is…Issue 705: Non-enumerable property fails to shadow inherited enumerable property from for-in
Test it in Firefox, and you’ll get the expected result.