Skip to content
Proxy and Reflect
step 1/5

Reading — step 1 of 5

Learn

~1 min readProxy and Memory

Proxy intercepts operations on an object — get, set, has, delete, function calls. Used for reactive frameworks (Vue 3), validation, observability, lazy loading.

javascript

Trap methods you can implement on the handler:

  • get(target, prop, receiver) — property read
  • set(target, prop, value, receiver) — assignment
  • has(target, prop)in operator
  • deleteProperty(target, prop)delete obj.x
  • apply(target, thisArg, args) — function call
  • construct(target, args, newTarget)new
  • ownKeys, getOwnPropertyDescriptor, defineProperty, getPrototypeOf, setPrototypeOf, isExtensible, preventExtensions

Real-world: validation:

javascript

Reflect is a companion API — Reflect.get(obj, prop) mirrors obj[prop], but in function form. Useful inside Proxy traps to delegate cleanly:

javascript

React 17/Vue 3 reactivity, mobx, and Object.observe (deprecated) all build on Proxy.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…