Inheritance with the prototype chain
JavaScript objects are dynamic "bags" of properties (referred to as own properties). JavaScript objects have a link to a prototype object. When trying to access a property of an object, the property will not only be sought on the object but on the prototype of the object, the prototype of the prototype, and so on until either a property with a matching name is found or the end of the prototype chain is reached.
Following the ECMAScript standard, the notation someObject.[[Prototype]]
is used to designate the prototype of someObject
. Since ECMAScript 2015, the [[Prototype]]
is accessed using the accessors Object.getPrototypeOf()
and Object.setPrototypeOf()
. This is equivalent to the JavaScript property __proto__
which is non-standard but de-facto implemented by many browsers.
It should not be confused with the func
.prototype
property of functions, which instead specifies the [[Prototype]]
to be assigned to all instances of objects created by the given function when used as a constructor. The Object.prototype
property represents the Object
prototype object.
Last updated