Proxies & Reflect in JavaScript
Proxies intercept object operations through handler traps: get/set/has/deleteProperty plus function traps (apply/construct), with Reflect.* providing the default behaviors to wrap. Validation (reject bad sets), logging, defaults, and revokable membranes (Proxy.revocable) all build from a dozen traps.
Invariants constrain: non-configurable properties can't lie about existence or values, and private fields ignore proxies entirely. Proxies power frameworks (Vue reactivity, Immer drafts) far more than application code — understand them to read those systems, reach for them sparingly yourself.
Traps intercept operations
new Proxy(target, { get(t, k) {...}, set(t, k, v) {...} }) hooks reads and writes around the target.
Reflect forwards defaults
Reflect.get/set perform the normal operation — traps validate then forward, customizing edges only.
Invariants limit lies
Non-configurable, non-writable properties must report truthfully — proxies can't fake the locked-down.
Frameworks use most
Reactivity systems and mocks lean on proxies; application code usually prefers plain validation.
let user = new Proxy({ age: 30 }, { set(t, k, v) { if (k === "age" && v < 0) return false; return Reflect.set(t, k, v); },});user.age = -5;console.log(user.age);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.