JS Built-ins
← Proxy13 / 100
Proxysetbeginner

Proxy set trap β€” passthrough (no trap)

πŸ“– Usage Example
const log = []
const p = new Proxy({}, {
  set: (t, k, v) => { log.push(String(k) + '=' + v); t[k] = v; return true }
})
p.x = 10
console.log(log) // β†’ ["x=10"]

The set trap intercepts property assignments on a proxy, letting you validate or observe writes before they reach the target.

set β€” no trap means passthrough

Without a set trap the proxy forwards assignments directly to the target.

Challenge: Verify that after p.x = 'hello', reading p.x returns 'hello'.

πŸ’‘ Hints (1)
  • β€’ Without a `set` trap, writes go directly to the target object.