get and set Traps
Customize property reads and writes.
The get and set Traps
The get and set traps are the most-used proxy hooks. They intercept reading and writing properties, letting you transform values, validate input, or log access.
get Trap Signature
get(target, property, receiver) runs on every property read. Return whatever you want the caller to see.
const proxy = new Proxy({ price: 10 }, {
get(target, prop) {
return target[prop];
}
});
console.log(proxy.price);All lessons in this course
- Creating a Proxy
- get and set Traps
- The Reflect API
- Practical Proxy Use Cases