Observe operations
Record reads or writes for debugging, auditing, or metrics.
JavaScript · Class
The Proxy() constructor creates a proxy that wraps a target object and can intercept selected fundamental operations. A handler supplies trap functions for customizing those operations.
A Proxy wraps a target object and uses handler trap functions to intercept selected fundamental operations, such as property reads and writes. Each trap can customize the operation or delegate to the corresponding Reflect method. The target may be an object, array, function, or another proxy.
new Proxy(target, handler)| Name | Type | Description |
|---|---|---|
target | object | The object to wrap. It may be an array, function, or another proxy. |
handler | object | An object whose function-valued properties define the proxy's custom behavior. |
A new Proxy object that wraps target and applies the behavior defined by handler.
const user = { name: "Ada" };
const observed = new Proxy(user, {
get(target, property, receiver) {
console.log(`Reading ${String(property)}`);
return Reflect.get(target, property, receiver);
},
});
console.log(observed.name);The proxy logs property reads, then delegates the actual lookup to Reflect.get.
Record reads or writes for debugging, auditing, or metrics.
Reject invalid assignments or enforce object invariants at runtime.
Present computed, normalized, or virtual properties through an object-like interface.
Hide or transform selected values while exposing a compatible object API.
Proxy.revocable()Reflecthandler.get()handler.set()