JavaScript Object setPrototypeOf() method
sets the prototype of a specified object to another object or null

Object.setPrototypeOf() static method sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.

syntax

Object.setPrototypeOf(obj, prototype)

obj The object which is to have its prototype set.

prototype The object's new prototype (an object or null).

TypeError thrown in one of the following cases ↴

obj parameter is undefined or null ↴

obj parameter is non-extensible, or it's an immutable prototype exotic object, such as Object.prototype or window

prototype parameter is not an object or null.

However, the error is not thrown if the new prototype is the same value as the original prototype of obj.

Object.setPrototypeOf() is generally considered the proper way to set the prototype of an object ↴

You should always use it in favor of the deprecated Object.prototype.__proto__ accessor.

Warning: Changing the [[Prototype]] of an object is, by the nature of how modern JavaScript engines optimize property accesses, currently a very slow operation in every browser and JavaScript engine.

syntax description
set prototype of myObj to myProto
Object.setPrototypeOf(obj, prototype)