Prototype-Based Inheritance (Definition)

JavaScript supports an inheritance chain based on prototypes.


ECMAScript edition - 2

JavaScript supports an inheritance chain based on prototypes. Every constructor has an associated prototype and every object created with that constructor has a link to the prototype as an integral part of its instantiation. This is called the object's prototype.

A prototype may have an implicit reference to it's parent prototype. This provides inheritance through a prototype chain that is analogous to the super-class and sub-class mechanisms in a class-based object-oriented language.

This allows for properties to be overridden or provided by parent prototypes if the properties are not implemented in the target object.

In a class-based object-oriented environment, as a general rule, state values are embodied in object instances of a class but methods are contained in the classes themselves so the inheritance only projects structure and behavior down through the sub-classing mechanism.

In the prototype-based inheritance the state AND methods are carried by the objects so structure, state and behavior are all inherited down the prototype chain.

All objects that do not contain a particular property and that are descended via the inheritance tree from a single object that does contain that property will all share that one single property instance.

See also:function( ... ) ..., Hierarchy of objects, Inheritance, Namespace, Prototype chain, prototype property, Shared Property

insert figure 0023


ECMA 262 edition 2 - section - 4.2.1

ECMA 262 edition 3 - section - 4.2.1