When using square brackets around __proto__ in a object, __proto__ is enumerable. When no square brackets are provided, __proto__ is not enumerable.
Example:
obj = {"__proto__": "Hello"}
for (var k in obj)
{
console.log(k)
};
// No Output
Using Square Brackets
obj = {["__proto__"]: "Hello"}
for (var k in obj)
{
console.log(k)
};
// Output:
// __proto__
I understand that using the square brackets computed property names, but I don't understand why one would be enumerable and another would not.
This is described in the specification. Computed property names of
__proto__are specifically excluded from theisProtoSettercheck, whereas normal string values of__proto__are permitted:The
isProtoSetterflag, when true, indicates that the created object should have an internal prototype of the value paired with that key. The__proto__for the standard internal prototype of an object is not enumerable - it exists onObject.prototype:When false, it's equivalent to having a plain property which is named
__proto__, and plain properties in object initializers become enumerable.