handler.getOwnPropertyDescriptor()
The handler.getOwnPropertyDescriptor() method is a trap for Object.getOwnPropertyDescriptor().
Syntax
new Proxy(target, {
  getOwnPropertyDescriptor(target, prop) {
  }
});
Parameters
The following parameters are passed to the getOwnPropertyDescriptor() method. this is bound to the handler.
- target- : The target object.
 
- prop- : The name of the property whose description should be retrieved.
 
Return value
The getOwnPropertyDescriptor() method must return an object or undefined.
Description
The handler.getOwnPropertyDescriptor() method is a trap for Object.getOwnPropertyDescriptor().
Interceptions
This trap can intercept these operations:
Or any other operation that invokes the [[GetOwnProperty]] internal method.
Invariants
If the following invariants are violated, the trap throws a TypeError when invoked.
- getOwnPropertyDescriptor()must return an object or- undefined.
- A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
- A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.
- A property cannot be reported as existent, if it does not exists as an own property of the target object and the target object is not extensible.
- A property cannot be reported as non-configurable, if it does not exists as an own property of the target object or if it exists as a configurable own property of the target object.
- The result of Object.getOwnPropertyDescriptor(target)can be applied to the target object usingObject.defineProperty()and will not throw an exception.