JavaScript Object.setPrototypeOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

Object.setPrototypeOf(obj, proto) sets the prototype of obj to proto (or null). The object then inherits from that prototype.

For brand-new objects, prefer Object.create(proto). Changing prototypes on existing objects can be slow and hard to follow, so use setPrototypeOf only when you must.

Syntax

Call Object.setPrototypeOf() like this. Start with this line.

JavaScript
Object.setPrototypeOf(obj, proto)
CallWhat it does
Object.setPrototypeOf(obj, proto)Makes obj inherit from proto.
Object.setPrototypeOf(obj, null)Removes the prototype chain (no inherited Object methods).
Object.create(proto)Preferred way to make a new object with a given prototype.

proto must be an object or null. Returns obj. Fails on non-extensible objects.

Library declarations
JavaScript
Object.setPrototypeOf(obj, proto)
JavaScript
Object.setPrototypeOf(o: any, proto: object | null): any

Parameters

ParameterDescription
objRequired. The object whose prototype you want to change.
protoRequired. The new prototype object, or null for no prototype.

Return Value

Return ValueDescription
objectThe same object obj, now linked to the new prototype.

JavaScript Examples

Link an Object to a Prototype

Give a user object methods from a shared prototype.

JavaScript
var personProto = {
  greet: function () {
    return "Hi, " + this.name;
  }
};

var user = { name: "Ada" };
Object.setPrototypeOf(user, personProto);

console.log(user.greet());
console.log(Object.getPrototypeOf(user) === personProto);
Try It Yourself

How It Works

  1. Shared methods. personProto holds a greet function.
  2. Link the object. setPrototypeOf makes user inherit from that prototype.
  3. Call inherited method. user.greet() works, and getPrototypeOf confirms the link.

Prefer Object.create for New Objects

Build the object with the right prototype from the start.

JavaScript
var animal = {
  speak: function () {
    return this.sound;
  }
};

var dog = Object.create(animal);
dog.sound = "woof";

console.log(dog.speak());
console.log(Object.getPrototypeOf(dog) === animal);
Try It Yourself

How It Works

  1. Create with proto. Object.create(animal) sets the prototype immediately.
  2. Add own data. sound is an own property on dog.
  3. No later rewrite. You avoid changing the prototype after the object already exists.

Set Prototype to null

A null prototype object has no inherited methods like toString.

JavaScript
var mapLike = { a: 1 };
Object.setPrototypeOf(mapLike, null);

console.log(Object.getPrototypeOf(mapLike));
console.log("toString" in mapLike);
console.log(mapLike.a);
Try It Yourself

How It Works

  1. No prototype. getPrototypeOf returns null.
  2. No inherited methods. toString is not found on the chain.
  3. Own keys work. Own data like a is still readable.

Browser & Runtime Support

Object.setPrototypeOf() was added in ES6 (ES2015) and is supported in modern browsers and Node.js.

✓ ES6 · Baseline

Object.setPrototypeOf()

Available in all current browsers and runtimes. For new objects, Object.create is usually clearer.

100% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Object.setPrototypeOf Excellent

Bottom line: Safe in modern environments. Prefer Object.create when you control object creation.

Frequently Asked Questions

It changes an object’s prototype so the object inherits from a different object (or from nothing if you pass null).
Prefer Object.create for new objects. Use setPrototypeOf only when you must change an existing object’s prototype.
Yes. Object.setPrototypeOf(obj, null) removes inheritance. Handy for dictionary-like objects.
Changing prototypes later can make code harder to understand and can be slower for engines that optimize stable shapes.
Use Object.getPrototypeOf(obj). Avoid the older __proto__ property in new code.

Next: values()

List an object’s own enumerable values.

values() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful