This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The handler.get() method is a trap for the [[Get]] object internal method, which is used by operations such as property accessors.
const monster = {
secret: "easily scared",
eyeCount: 4,
};
const handler = {
get(target, prop, receiver) {
if (prop === "secret") {
return `${target.secret.substring(0, 4)} ... shhhh!`;
}
return Reflect.get(...arguments);
},
};
const proxy = new Proxy(monster, handler);
console.log(proxy.eyeCount);
// Expected output: 4
console.log(proxy.secret);
// Expected output: "easi ... shhhh!"
new Proxy(target, {
get(target, property, receiver) {
}
})
The following parameters are passed to the get() method. this is bound to the handler.
targetThe target object.
propertyA string or Symbol representing the property name.
receiverThe this value for getters; see Reflect.get(). This is usually either the proxy itself or an object that inherits from the proxy.
The get() method can return any value, representing the property value.
This trap can intercept these operations:
proxy[foo] and proxy.bar
Reflect.get()Or any other operation that invokes the [[Get]] internal method.
The proxy's [[Get]] internal method throws a TypeError if the handler definition violates one of the following invariants:
Reflect.getOwnPropertyDescriptor() returns configurable: false, writable: false for the property on target, then the trap must return the same value as the value attribute in the target's property descriptor.undefined, if the corresponding target object property is a non-configurable own accessor property that has an undefined getter. That is, if Reflect.getOwnPropertyDescriptor() returns configurable: false, get: undefined for the property on target, then the trap must return undefined.The following code traps getting a property value.
const p = new Proxy(
{},
{
get(target, property, receiver) {
console.log(`called: ${property}`);
return 10;
},
},
);
console.log(p.a);
// "called: a"
// 10
The following code violates an invariant.
const obj = {};
Object.defineProperty(obj, "a", {
configurable: false,
enumerable: false,
value: 10,
writable: false,
});
const p = new Proxy(obj, {
get(target, property) {
return 20;
},
});
p.a; // TypeError is thrown
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
get |
49 | 12 | 18 | 36 | 10 | 49 | 18 | 36 | 10 | 5.0 | 49 | 10 | 1.0.0 | 1.0 | 6.0.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/get