PROXY TRAPS AND REFLECT METHODS
Proxies are able to trap thirteen different fundamental operations. Each has its own entry in the Reflect API, parameters, associated ECMAScript operations, and invariants.
As demonstrated earlier, several different JavaScript operations may invoke the same trap handler. However, for any single operation that is performed on a proxy object, only one trap handler will ever be called; there is no overlap of trap coverage.
All traps will also intercept their corresponding Reflect API operations if they are invoked on the proxy.
get()
The get()
trap is called inside operations that retrieve a property value. Its corresponding Reflect API method is Reflect.get()
.
const myTarget = {};
const proxy = new Proxy(myTarget, {
get(target, property, receiver) {
console.log('get()');
return Reflect.get(…arguments)
}
});
proxy.foo;
// get()
Return value
The return value is unrestricted.
Intercepted operations
proxy.property
proxy[property...