Function: prototype
The prototype data property of a Function instance is used when the function is used as a constructor with the new operator. It will become the new object's prototype.
Note:
Not all Function objects have the prototype property — see description.
Value
An object.
Property attributes of Function: prototype | |
|---|---|
| Writable | yes |
| Enumerable | no |
| Configurable | no |
Note:
Classes are a type of function, so most of the description here applies to the prototype property of classes too. The only salient difference is that the prototype property of a class is not writable.
Description
When a function is called with new, the constructor's prototype property will become the resulting object's prototype.
function Ctor() {}
const inst = new Ctor();
console.log(Object.getPrototypeOf(inst) === Ctor.prototype); // true
You can read Inheritance and the prototype chain for more information about the interactions between a constructor function's prototype property and the resulting object's prototype.
A function having a prototype property is not sufficient for it to be eligible as a constructor. Generator functions have a prototype property, but cannot be called with new:
async function* asyncGeneratorFunction() {}
function* generatorFunction() {}
Instead, generator functions' prototype property is used when they are called without new. The prototype property will become the returned Generator object's prototype.
In addition, some functions may have a prototype but throw unconditionally when called with new. For example, the Symbol() and BigInt() functions throw when called with new, because Symbol.prototype and BigInt.prototype are only intended to provide methods for the primitive values, but the wrapper objects should not be directly constructed.
The following functions do not have prototype, and are therefore ineligible as constructors, even if a prototype property is later manually assigned:
const method = { foo() {} }.foo;
const arrowFunction = () => {};
async function asyncFunction() {}
The following are valid constructors that have prototype:
class Class {}
function fn() {}
A bound function does not have a prototype property, but may be constructable. When it's constructed, the target function is constructed instead, and if the target function is constructable, it would return a normal instance.
const boundFunction = function () {}.bind(null);
A function's prototype property, by default, is a plain object with one property: constructor, which is a reference to the function itself. The constructor property is writable, non-enumerable, and configurable. If the function is created as a class with extends, then the prototype object's prototype is ParentClass.prototype instead of Object.prototype.
If the prototype of a function is reassigned with something other than an Object, when the function is called with new, the returned object's prototype would be Object.prototype instead. (In other words, new ignores the prototype property and constructs a plain object.)
function Ctor() {}
Ctor.prototype = 3;
console.log(Object.getPrototypeOf(new Ctor()) === Object.prototype); // true
Two JavaScript constructors have prototype properties with slightly more complicated semantics:
Object.prototypeserves as the root of the prototype chain for most objects. Its prototype isnulland it does not allow resetting its prototype.Proxyis the only built-in class without aprototypeproperty.Proxyinstances have no shared prototype chain or properties given by theProxyclass (they each define their own behaviors).
For legacy reasons, five other JavaScript constructors have prototype properties that are also instances of their classes. Other than instanceof returning false (because instanceof checks the prototype chain), they possess all the private slots and instance properties of actual instances.
Array.prototypeis anArrayobject that's initially empty. You can pass it toArray.isArray(), assign to its indices, read itslength, and call methods likeArray.prototype.push(1).Function.prototypeis aFunctionobject that returnsundefinedwhen called with any arguments. It has alengthproperty of value0and anameproperty of value"". It cannot be constructed and has noprototypeproperty.Number.prototypeis aNumberobject that wraps the value0.Boolean.prototypeis aBooleanobject that wraps the valuefalse.String.prototypeis aStringobject that wraps the value"". It has alengthproperty of value0.
RegExp.prototype used to be a RegExp object, but it's now a plain object special-cased by the source and different flag accessors like global.
Examples
>Changing the prototype of all instances by mutating the prototype property
jsfunction Ctor() {}
const p1 = new Ctor();
const p2 = new Ctor();
Ctor.prototype.prop = 1;
console.log(p1.prop); // 1
console.log(p2.prop); // 1
Adding a non-method property to a class's prototype property
Class fields add properties to each instance. Class methods declare function properties on the prototype. However, there's no way to add a non-function property to the prototype. In case you want to share static data between all instances (for example, Error.prototype.name is the same between all error instances), you can manually assign it on the prototype of a class.
class Dog {
constructor(name) {
this.name = name;
}
}
Dog.prototype.species = "dog";
console.log(new Dog("Jack").species); // "dog"
This can be made more ergonomic using static initialization blocks, which are called when the class is initialized.
jsclass Dog {
static {
Dog.prototype.species = "dog";
}
constructor(name) {
this.name = name;
}
}
console.log(new Dog("Jack").species); // "dog"
The Function.prototype object
For legacy reasons, Function.prototype is also a Function object that returns undefined when called with any arguments. It has a length property of value 0 and a name property of value "". It cannot be constructed and has no prototype property.
console.log(Function.prototype()); // undefined
console.log(Function.prototype.toString()); // function () { [native code] }
Other subclasses do not share this behavior—for example, GeneratorFunction.prototype is just a plain object that inherits from Function.prototype and is not callable. It still inherits name and length from Function.prototype, though.
const GeneratorFunction = function* () {}.constructor;
GeneratorFunction.prototype(); // TypeError: GeneratorFunction.prototype is not a function
GeneratorFunction.prototype.toString(); // TypeError: Function.prototype.toString requires that 'this' be a Function
Specifications
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-function-instances-prototype > |
See also
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Nov 23, 2026 by MDN contributors.
View this page on GitHub • Report a problem with this content