Skip to content

API Proxy

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

Proxy

Dynamic interception of object property reads and writes.

Script API Reference

Overview

Proxy wraps a target object and routes property reads and writes through handler functions supplied by the caller. Use it for computed views, access logging, or validation layers over an existing object.

Caution

Handlers must be explicit and free of recursive side effects. Reading or writing the same proxy unconditionally from inside a handler causes unbounded re-entry.

Constructors

new Proxy(target, options)

Parameters

Name Type Required Description
target object Yes Object to wrap.
options object Yes Handler object that must provide both get(obj, key) and set(obj, key, value).

Returns

Proxy — the proxy object.

Behavior

Both handlers are required. An options object that omits get or set is an invalid construction.

Example

var source = { count: 1 };
var proxy = new Proxy(source, {
    get: (obj, key) => obj[key],
    set: (obj, key, value) => { obj[key] = value; return value; }
});
proxy.count = 2;
return proxy.count; // 2

Clone this wiki locally