A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy below:

Proxy() constructor - JavaScript | MDN

Proxy() constructor

Baseline Widely available

The Proxy() constructor creates Proxy objects.

Syntax
new Proxy(target, handler)

Note: Proxy() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters
target

A target object to wrap with Proxy. It can be any sort of object, including a native array, a function, or even another proxy.

handler

An object whose properties are functions that define the behavior of the proxy when an operation is performed on it.

Description

Use the Proxy() constructor to create a new Proxy object. This constructor takes two mandatory arguments:

An empty handler will create a proxy that behaves, in almost all respects, exactly like the target. By defining any of a set group of functions on the handler object, you can customize specific aspects of the proxy's behavior. For example, by defining get() you can provide a customized version of the target's property accessor.

Handler functions Examples Selectively proxy property accessors

In this example the target has two properties, notProxied and proxied. We define a handler that returns a different value for proxied, and lets any other accesses through to the target.

const target = {
  notProxied: "original value",
  proxied: "original value",
};

const handler = {
  get(target, prop, receiver) {
    if (prop === "proxied") {
      return "replaced value";
    }
    return Reflect.get(...arguments);
  },
};

const proxy = new Proxy(target, handler);

console.log(proxy.notProxied); // "original value"
console.log(proxy.proxied); // "replaced value"
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3