The getOwnPropertyDescriptor trap is executed when we retrieve the descriptor of a property by using the Object.getOwnPropertyDescriptor() method. It takes two parameters--that is, the target object and the name of the property.
This trap must return a descriptor object or undefined. The undefined value is returned if the property doesn't exist.
Here is a code example that demonstrates how to use the getOwnPropertyDescriptor trap:
const proxy = new Proxy({age: 12}, { getOwnPropertyDescriptor(target, property) { return Object.getOwnPropertyDescriptor(target, property); } }); const descriptor = Reflect.getOwnPropertyDescriptor(proxy, "age"); console.log("Enumerable: " + descriptor.enumerable); ...