Friday, December 16, 2022

Proxy Objects

Proxy Objects

A proxy object is an exotic object whose essential internal methods are partially implemented using ECMAScript code. Every proxy object has an internal slot called [[ProxyHandler]]. The value of [[ProxyHandler]] is an object, called the proxy's handler object, or null. Every proxy object also has an internal slot called [[ProxyTarget]] whose value is either an object or the null value. This object is called the proxy's target object.

When a handler method is called to provide the implementation of a proxy object internal method, the handler method is passed the proxy's target object as a parameter. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy's target object if the handler object does not have a method corresponding to the internal trap.

[[GetPrototypeOf]] ( )

  1. Let trap be ? GetMethod(handler, "getPrototypeOf").
  2. If not IsExtensible(target) or trap is undefined, Return ? target.[[GetPrototypeOf]]().
  3. return call trap on target to get target's prototype

[[SetPrototypeOf]] ( V )

  1. if not IsExtensible(target), return true
  2. Let trap be ? GetMethod(handler, "setPrototypeOf").
  3. If trap is undefined, Return ? target.[[SetPrototypeOf]](V).
  4. return call trap on target&V to set target's prototype

No comments:

Post a Comment