JavaScript Prototypes, a Pocket Reference

AJ Meyghani
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 to b, and b links to m
  • 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 of a, and m the prototype of b.
  • 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 at a itself. If it cannot find it there, it will then look at b. If it can't find it in b, then it will look in m, and eventually if it…

--

--