JS Built-ins
← Proxy11 / 100
Proxysetintermediate

Proxy set trap β€” log key on set

πŸ“– 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.

Proxy set trap

The set trap intercepts property assignments. Use it to observe or transform writes.

Challenge: Verify that setting p.x = 1 pushes 'x' into a log array.

πŸ’‘ Hints (1)
  • β€’ The `set` trap receives `(target, key, value, receiver)`. Return `true` to indicate success.