Skip to main content
Version: 3.4.0

Proxy()

The Proxy() constructor is used to create 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:

  • target is the object for which you want to create the proxy
  • handler is the object that defines the custom behavior of the proxy.

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

This section lists all the handler functions you can define. Handler functions are sometimes called traps, because they trap calls to the underlying target object.