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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.setPrototypeOf(obj, prototype)

Parameters

ParameterDescription
obj The object to inspect or change.
prototype The new prototype, or null.

Return value

The object.

Examples

Add inherited methodsTry it yourself
const base = { greet() { return "hi " + this.name; } };
const user = { name: "Ada" };
Object.setPrototypeOf(user, base);
console.log(user.greet());

Output

hi Ada
Remove all inherited methodsTry it yourself
const o = Object.setPrototypeOf({ a: 1 }, null);
console.log(typeof o.toString);

Output

undefined

Version history

VersionChange
JavaScript ES2015Added

Was this page helpful?