JS: Object.getOwnPropertyDescriptors
(new in ECMAScript 2017)
Object.getOwnPropertyDescriptors(obj)-
Return Property Descriptor of all own properties of a object.
The return value is a object, has this form
{ k1: descriptor1, k2: descriptor2, etc }.If obj is not a object, it is first converted to a object type.
// object with a string key and symbol key const jj = { "p": 3, [Symbol()]: 4, }; console.log(Object.getOwnPropertyDescriptors(jj)); /* { p: { value: 3, writable: true, enumerable: true, configurable: true }, [Symbol()]: { value: 4, writable: true, enumerable: true, configurable: true } } */
Edge cases
Arg is not object
// If obj is not a object, it is first converted to a object type console.log(Object.getOwnPropertyDescriptors(3)); // {} console.assert(typeof Object.getOwnPropertyDescriptors(3));
Object sans properties
// object without properties console.log(Object.getOwnPropertyDescriptors({})); // {} // result is empty object console.assert(Object.keys(Object.getOwnPropertyDescriptors({})).length === 0);
JavaScript. Define Properties and attributes.
- JS: Property Attributes
- JS: Enumerable Property
- JS: Property Descriptor
- JS: Object.create
- JS: Object.defineProperty ❌
- JS: Reflect.defineProperty
- JS: Object.defineProperties
- JS: Object.prototype.propertyIsEnumerable ❌
- JS: Object.getOwnPropertyDescriptor ❌
- JS: Reflect.getOwnPropertyDescriptor
- JS: Object.getOwnPropertyDescriptors