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 readset(target, prop, value, receiver)— assignmenthas(target, prop)—inoperatordeleteProperty(target, prop)—delete obj.xapply(target, thisArg, args)— function callconstruct(target, args, newTarget)—newownKeys,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…