JS: Reflect.getOwnPropertyDescriptor
New in JS2015.
Reflect.getOwnPropertyDescriptor(obj, key)
-
- Return the Property Attributes in the form of Property Descriptor.
- If the property doesn't exist, returns
undefined
. - If obj is not object, throw a TypeError exception.
const jj = { p: 4 }; console.log( JSON.stringify(Reflect.getOwnPropertyDescriptor(jj, "p")) === '{"value":4,"writable":true,"enumerable":true,"configurable":true}', ); // non-exist key console.log( Reflect.getOwnPropertyDescriptor(jj, "yy") === undefined, );
Difference Between Object.getOwnPropertyDescriptor vs Reflect.getOwnPropertyDescriptor
- Object.getOwnPropertyDescriptor will first convert 1st arg to object.
- Reflect.getOwnPropertyDescriptor return error if arg is not object.