Object.getOwnPropertyDescriptorsbeginner// Inspect all property descriptors at once
const obj = { a: 1, b: 2 }
Object.getOwnPropertyDescriptors(obj)
// β { a: { value: 1, writable: true, ... }, b: { value: 2, ... } }Use Object.getOwnPropertyDescriptors() to get all property descriptors of an object, useful when doing a complete clone.
Object.getOwnPropertyDescriptors(obj) returns an object mapping every own property to its full descriptor. Unlike Object.getOwnPropertyDescriptor, it covers all properties at once.
Challenge: Implement getAllDescriptors(obj) that returns the full descriptors map.
getAllDescriptors({ a: 1 })
// β { a: { value: 1, writable: true, enumerable: true, configurable: true } }