undefinedfix
Sign in

How to judge whether it can be enumerated

r4cc00n edited in Sat, 02 Jul 2022
// getFoo is a property which isn't enumerable
var myObj = Object.create({}, {
  getFoo: {
    value: function () { return this.foo; }
  } 
});
myObj.foo = 1;
console.log(Object.keys(myObj)); // console: ['foo']

Why is getfoo a bad property

2 Replies
gjotc
commented on Sat, 02 Jul 2022

Determine whether the property can be enumerated obj.propertyIsEnumerable (prop) link description

Object.create The second parameter of () and Object.defineProperties The second parameter of () is similar to the object that defines its enumerable property or modified property descriptor. In the second parameter, you do not specify enumerable, but the default value is false, so getfoo is an enumerable property. Object.create ()

Object.defineProperties ()

itsaunix
commented on Sat, 02 Jul 2022
Object.getOwnPropertyDescriptor
lock This question has been locked and the reply function has been disabled.