JavaScript (ES2026) reference · Object Methods
JavaScript Object.setPrototypeOf() Method
Change the prototype of an existing object. It is slow in most engines; prefer Object.create() or classes.
JavaScript (ES2026) Since ES2015
Syntax
Object.setPrototypeOf(obj, prototype)
Parameters
| Parameter | Description |
|---|---|
obj |
The object to inspect or change. |
prototype |
The new prototype, or null. |
Return value
The object.
Examples
const base = { greet() { return "hi " + this.name; } };
const user = { name: "Ada" };
Object.setPrototypeOf(user, base);
console.log(user.greet());
Output
hi Ada
const o = Object.setPrototypeOf({ a: 1 }, null);
console.log(typeof o.toString);
Output
undefined
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
Object.getPrototypeOf()· Return the prototype of an object: the object it inherits methods and properties from, or null.Object.create()· Create a new object with the given prototype (or null for an object with no inherited properties at all).- JavaScript Objects · tutorial