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
.
- : The object's new prototype or
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, theprototype
parameter must be the same value asObject.getPrototypeOf(target)
.