The full set of traps
Proxy can intercept many internal operations:
new Proxy(target, {
get, set, has, apply, construct,
getPrototypeOf, setPrototypeOf,
defineProperty, deleteProperty,
ownKeys, getOwnPropertyDescriptor
});
Each trap corresponds to an ECMAScript internal method. apply intercepts function calls; construct intercepts new; ownKeys intercepts Object.keys. Reflect provides matching methods for each trap.
Invariants and Revocable proxies
Proxies must respect target invariants, or the engine throws:
const frozen = Object.freeze({ x: 1 });
const p = new Proxy(frozen, {
set() { return true; } // would violate frozen invariant
});
p.x = 2; // TypeError: property is frozen
Proxy.revocable creates a proxy that can be permanently disabled:
const { proxy, revoke } = Proxy.revocable(target, { get(t, prop) { return t[prop]; } });
revoke();
proxy.x; // TypeError: proxy revoked
Use revocable proxies for resource cleanup and test doubles.