JavaScript Prototypes, a Pocket Reference
13 min readOct 6, 2018
There are different ways to interpret the prototype concept in JavaScript, but it can be explained very easily in one sentence:
“In JavaScript, prototypes are objects that facilitate linking of objects and delegation of methods or properties”
That’s really it. The most confusing part about the prototype concept is just the terminology, but the concept itself is pretty straightforward. The diagram below demonstrates the idea in more detail:
- The boxes represent objects
- The arrow shows the link direction:
a
links tob
, andb
links tom
- The links form the prototype chain for these objects
m
is the mother object which contains all the methods common to all objects in JavaScript[[p]]
is the internal property of an object that points to another object. Confusingly enough, this property is known as the[[prototype]]
in the specification- In this diagram,
b
is known as the prototype ofa
, andm
the prototype ofb
. - Property and method look up follows the prototype chain. That is, if you want to look up a property in
a
, JavaScript will first look ata
itself. If it cannot find it there, it will then look atb
. If it can't find it inb
, then it will look inm
, and eventually if it…