JS: Object.defineProperty 👎
Object.defineProperty
Object.defineProperty(obj, key, descriptor)-
- Create or modify Property Attributes of a single property.
- Return the modified object.
descriptor is Property Descriptor.
🟢 tip: better is Reflect.defineProperty.
// create a property that's not enumerable const xx = {}; Object.defineProperty(xx, "pp", { value: 3, writable: true, enumerable: false, configurable: true, }); console.assert(xx.pp === 3); console.assert(Reflect.getOwnPropertyDescriptor(xx, "pp").enumerable === false);