| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_set_prototype | [Back] [Original] |
Get to know MDN better
The JavaScript exception "can't set prototype of this object" occurs when attempting to set the prototype of an object, but the object's prototype is frozen, either by being a built-in immutable prototype object, or by being non-extensible.
TypeError: Immutable prototype object 'Object.prototype' cannot have their prototype set (V8-based) TypeError: #<Object> is not extensible (V8-based) TypeError: can't set prototype of this object (Firefox) TypeError: Cannot set prototype of immutable prototype object (Safari) TypeError: Attempted to assign to readonly property. (Safari)
TypeError
You are using one of the prototype-mutating methodsmost notably, Object.setPrototypeOf()on an object whose prototype is immutable. Some built-in objects have immutable prototypes, such as Object.prototype and window, for security reasons. User objects can also prevent prototype changes by using Object.preventExtensions(), Object.seal(), or Object.freeze().
A selected few built-in objects have immutable prototypes. For example, you cannot change the prototype of Object.prototype:
Object.setPrototypeOf(Object.prototype, {});
This prevents you from being able to arbitrarily change the behavior of all objects in the system. The prototype of Object.prototype is always null. However, other built-in prototype objects, such as Function.prototype and Array.prototype, are not protected by default in this regard.
If you make an object non-extensible, you cannot change its prototype either:
const obj = {};
Object.preventExtensions(obj);
Object.setPrototypeOf(obj, {});
// TypeError: can't set prototype of this object
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |