Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The constructor data property of an Object instance returns a reference to the constructor function that created the instance object. Note that the value of this property is a reference to the function itself, not a string containing the function's name.
Note: This is a property of JavaScript objects. For the constructor method in classes, see its own reference page.
A reference to the constructor function that created the instance object.
| Writable | yes |
| Enumerable | no |
| Configurable | yes |
Note: This property is created by default on the prototype property of every constructor function and is inherited by all objects created by that constructor.
Any object (with the exception of null prototype objects) will have a constructor property on its [[Prototype]]. Objects created with literals will also have a constructor property that points to the constructor type for that object — for example, array literals create Array objects, and object literals create plain objects.
Note that constructor usually comes from the constructor's prototype property. If you have a longer prototype chain, you can usually expect every object in the chain to have a constructor property.
The following example creates a constructor (Tree) and an object of that type (theTree). The example then displays the constructor property for the object theTree.
This example displays the following output:
theTree.constructor is function Tree(name) { this.name = name; }One can assign the constructor property of non-primitives.
This does not overwrite the old constructor property — it was originally present on the instance's [[Prototype]], not as its own property.
But even when Object.getPrototypeOf(a).constructor is re-assigned, it won't change other behaviors of the object. For example, the behavior of instanceof is controlled by Symbol.hasInstance, not constructor:
There is nothing protecting the constructor property from being re-assigned or shadowed, so using it to detect the type of a variable should usually be avoided in favor of less fragile ways like instanceof and Symbol.toStringTag for objects, or typeof for primitives.
Every constructor has a prototype property, which will become the instance's [[Prototype]] when called via the new operator. ConstructorFunction.prototype.constructor will therefore become a property on the instance's [[Prototype]], as previously demonstrated.
However, if ConstructorFunction.prototype is re-assigned, the constructor property will be lost. For example, the following is a common way to create an inheritance pattern:
The constructor of instances of Child will be Parent due to Child.prototype being re-assigned.
This is usually not a big deal — the language almost never reads the constructor property of an object. The only exception is when using [Symbol.species] to create new instances of a class, but such cases are rare, and you should be using the extends syntax to subclass builtins anyway.
However, ensuring that Child.prototype.constructor always points to Child itself is crucial when some caller is using constructor to access the original class from an instance. Take the following case: the object has the create() method to create itself.
In the example above, an exception is thrown, since the constructor links to Parent. To avoid this, just assign the necessary constructor you are going to use.
Note that when manually adding the constructor property, it's crucial to make the property non-enumerable, so constructor won't be visited in for...in loops — as it normally isn't.
If the code above looks like too much boilerplate, you may also consider using Object.setPrototypeOf() to manipulate the prototype chain.
Object.setPrototypeOf() comes with its potential performance downsides because all previously created objects involved in the prototype chain have to be re-compiled; but if the above initialization code happens before Parent or CreatedConstructor are constructed, the effect should be minimal.
Let's consider one more involved case.
For this example to work properly, we can reassign the Parent's static properties to Child:
But even better, we can make the constructor functions themselves extend each other, as classes' extends do.
Again, using Object.setPrototypeOf() may have adverse performance effects, so make sure it happens immediately after the constructor declaration and before any instances are created — to avoid objects being "tainted".
Note: Manually updating or setting the constructor can lead to different and sometimes confusing consequences. To prevent this, just define the role of constructor in each specific case. In most cases, constructor is not used and reassigning it is not necessary.
| ECMAScript® 2027 Language Specification # sec-object.prototype.constructor |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.