Skip to main content
Version: 3.13.0

handler.construct()

The handler.construct() method is a trap for the new operator. In order for the new operation to be valid on the resulting Proxy object, the target used to initialize the proxy must itself have a [[Construct]] internal method (i.e. new target must be valid).

Syntax

new Proxy(target, {
construct(target, argumentsList, newTarget) {
}
});

Parameters

The following parameters are passed to the construct() method. this is bound to the handler.

  • target
    • : The target object.
  • argumentsList
    • : The list of arguments for the constructor.
  • newTarget
    • : The constructor that was originally called, p above.

Return value

The construct method must return an object.

Description

The handler.construct() method is a trap for the new operator.

Interceptions

This trap can intercept these operations:

Or any other operation that invokes the [[Construct]] internal method.

Invariants

If the following invariants are violated, the trap throws a TypeError when invoked.

  • The result must be an Object.