JavaScript Reflect.setPrototypeOf() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Static method

Definition

Reflect.setPrototypeOf(target, prototype) changes the prototype of an object: the object that it inherits from. After the call, the object can use the properties and methods of its new prototype.

It returns true when the change worked and false when it was not allowed, for example on an object that is not extensible. The older Object.setPrototypeOf() throws an error in those cases.

Remember
Reflect.setPrototypeOf(target, prototype)

changed             → true
not allowed         → false  (no error)

prototype must be an object or null
No loops: A cannot inherit from B if B inherits from A
Prefer Object.create() when you create objects

Syntax

Pass the object and the new prototype. The new prototype must be an object or null.

JavaScript
const canFly = { fly() { return "I can fly"; } };
const bird = { name: "Robin" };

console.log(Reflect.setPrototypeOf(bird, canFly));   // true
console.log(bird.fly());                             // I can fly
CallWhat it does
Reflect.setPrototypeOf(obj, proto)Make proto the prototype of obj.
Reflect.setPrototypeOf(obj, null)Remove the prototype completely.
Reflect.getPrototypeOf(obj)Read the prototype again to check.
Object.setPrototypeOf(obj, proto)The older version. It throws instead of returning false.

A standard JavaScript static method (ES2015) of the Reflect object: call it as Reflect.setPrototypeOf(). No import required. Siblings: Reflect.apply(), Reflect.construct(), Reflect.defineProperty(), Reflect.deleteProperty(), Reflect.get(), Reflect.getOwnPropertyDescriptor(), Reflect.getPrototypeOf(), Reflect.has(), Reflect.isExtensible(), Reflect.ownKeys(), Reflect.preventExtensions(), Reflect.set().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Reflect.setPrototypeOf(target, prototype)

// target    : an object
// prototype : an object or null
// returns   : true or false
// throws    : TypeError if target is not an object,
//             or prototype is neither an object nor null

Parameters

ParameterDescription
targetRequired. The object whose prototype you want to change. If it is not an object, a TypeError is thrown.
prototypeRequired. The new prototype: an object, or null for no prototype. Any other value throws a TypeError.

Return Value

Return ValueDescription
trueThe prototype was changed (or it was already the same).
falseThe change was not allowed: the object is not extensible, or the change would make a loop in the chain.
TypeError (thrown)target is not an object, or prototype is not an object or null.

JavaScript Examples

Example 1 — Change the Prototype of an Object

Give a plain object the methods of another object by changing its prototype.

JavaScript
const canFly = {
  fly() {
    return this.name + " can fly";
  }
};
const bird = { name: "Robin" };

console.log("Has fly: " + ("fly" in bird));
console.log("Result: " + Reflect.setPrototypeOf(bird, canFly));
console.log("Has fly: " + ("fly" in bird));
console.log(bird.fly());
console.log("Same prototype: " + (Reflect.getPrototypeOf(bird) === canFly));
Try It Yourself

How It Works

  1. Before. bird is a plain object, so it has no fly method.
  2. Change. Reflect.setPrototypeOf(bird, canFly) makes canFly the prototype of bird, and returns true.
  3. After. bird can call fly(), and this.name still reads from bird. getPrototypeOf() confirms the change.

Example 2 — Remove the Prototype with null

Pass null to cut an object off from Object.prototype. Then it no longer has methods like toString().

JavaScript
const data = { a: 1 };

console.log("Before: " + typeof data.toString);
console.log("Result: " + Reflect.setPrototypeOf(data, null));
console.log("After: " + typeof data.toString);
console.log("Prototype: " + Reflect.getPrototypeOf(data));
console.log("Own data: " + data.a);

try {
  Reflect.setPrototypeOf(data, undefined);
} catch (err) {
  console.log("With undefined: " + err.name);
}
Try It Yourself

How It Works

  1. Inherited by default. A plain object gets toString from Object.prototype, so the first line prints function.
  2. Cut off. After setPrototypeOf(data, null), the object inherits nothing. toString is gone, but its own property a still works.
  3. Not undefined. The new prototype must be an object or null. Passing undefined throws a TypeError.

Example 3 — When Reflect.setPrototypeOf() Returns false

Locked objects and loops in the chain cannot be changed. Reflect returns false, while Object.setPrototypeOf() throws. The catch block prints the error type only.

JavaScript
const base = {};
const locked = Object.preventExtensions({});

console.log("Locked object: " + Reflect.setPrototypeOf(locked, base));

try {
  Object.setPrototypeOf(locked, base);
} catch (err) {
  console.log("Object version: " + err.name);
}

const parent = {};
const child = Object.create(parent);
console.log("Loop: " + Reflect.setPrototypeOf(parent, child));
console.log("Same prototype again: " + Reflect.setPrototypeOf(child, parent));
Try It Yourself

How It Works

  1. Locked object. A non-extensible object cannot get a new prototype, so Reflect returns false and Object.setPrototypeOf() throws a TypeError.
  2. No loops. child already inherits from parent, so parent cannot inherit from child. The answer is false.
  3. Same value is fine. Setting the prototype to the one it already has counts as a success.

Browser & Runtime Support

Reflect.setPrototypeOf() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

Reflect.setPrototypeOf()

Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 49+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 42+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 36+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 49+ · Chromium based
Supported
Node.js 6+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
Reflect.setPrototypeOf() Excellent

Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Reflect at all.

Frequently Asked Questions

It changes the prototype of an object, so the object inherits properties and methods from a different object. It returns true if it worked and false if it did not.
Both change the prototype. Reflect.setPrototypeOf() returns true or false. Object.setPrototypeOf() returns the object and throws a TypeError when the change is not allowed.
Yes. Reflect.setPrototypeOf(obj, null) removes the prototype, so the object does not inherit anything, not even toString(). But undefined is not allowed and throws a TypeError.
Usually not. It can slow your code down, and it makes the code harder to follow. Prefer Object.create(proto), a class with extends, or a Map or composition when you can.
A prototype chain must end at null. If A inherits from B, B cannot also inherit from A, because a property lookup would go around forever. JavaScript refuses this and returns false.

Back to the Method Index

Return to the list of all Reflect methods and pick the next one to learn.

All Reflect methods →

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.

9 people found this page helpful