JS Built-ins
ProxyProxybeginner

Proxy() β€” transparent proxy

πŸ“– Usage Example
const target = { value: 42 }
const p = new Proxy(target, {
  get: (t, k) => k in t ? t[k] : 'default'
})
console.log(p.value)   // β†’ 42
console.log(p.missing) // β†’ 'default'

new Proxy(target, handler) creates a proxy that intercepts operations on the target object using trap methods in the handler.

Transparent proxy

A Proxy with an empty handler {} transparently forwards all operations to the target object.

Challenge: Verify that new Proxy({x: 1}, {}).x === 1.

πŸ’‘ Hints (1)
  • β€’ An empty handler `{}` means no traps β€” all operations pass through to the target.