Skip to main content
Version: 3.13.0

handler.setPrototypeOf()

The handler.setPrototypeOf() method is a trap for Object.setPrototypeOf().

Syntax

new Proxy(target, {
setPrototypeOf(target, prototype) {
}
});

Parameters

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

  • target
    • : The target object.
  • prototype
    • : The object's new prototype or null.

Return value

The setPrototypeOf() method returns true if the [[Prototype]] was successfully changed, otherwise false.

Description

The handler.setPrototypeOf() method is a trap for Object.setPrototypeOf().

Interceptions

This trap can intercept these operations:

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

Invariants

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

  • If target is not extensible, the prototype parameter must be the same value as Object.getPrototypeOf(target).