PrototypeJungle images/logo_alt.html
Kits Tutorial Draw Code Editor Text Editor Coding Guide About
Prototypes and Inheritance

The meaning and utility of the concept of a prototype, as employed in JavaScript, is general and fairly simple. Here is an explanation that does not involve programming:

When we say that B is a prototype for A (or A is an instance of B), we mean that whenever B has a property, such as a color, A will "inherit" that same color, unless explicitly stated otherwise. So in describing A, we don't have to repeat all the information about A that it inherits from B. Think of the effort we save in describing a scarab if we first let on that it is a kind of beetle.

A might inherit from B and B in turn from C. This is called a prototype chain. The basic structures from which JavaScript objects are made are property-to-value links, and prototype chains.

Here is an example. In the prototype structure, D, E, and F inherit from the prototype P, which in turn inherits from "Square". P specifies both a fill (interior color) and stroke (boundary color). In addition D specifies fill, and F, stroke. The 3 squares which result via the rules of inheritance from this structure are pictured on the far left. For example, the bottom square (F) inherits its fill from P, but its stroke is set in F itself.