Skip to content
Optimal Lab

Frontend · interactive

Prototypes and the prototype chain

JavaScript objects don't copy methods from classes. Each object links to a prototype, which links to another, up to Object.prototype. Reading a property walks that chain until it finds it, or reaches the end and returns undefined.

class Animal { speak() {} eat() {} }
class Dog extends Animal { bark() {} }
const rex = new Dog(); rex.name = "Rex"; rex.age = 3;
  1. rex (own properties)

    nameage
  2. ↓ [[Prototype]]

    Dog.prototype

    barkconstructor
  3. ↓ [[Prototype]]

    Animal.prototype

    speakeat
  4. ↓ [[Prototype]]

    Object.prototype

    toStringhasOwnProperty
  5. ↓ null

rex.speak → found on Animal.prototype

Not on rex, so the engine follows the chain: 3 hops to Animal.prototype. Every Dog shares that one function.

Read rex.

  1. 1

  2. 2

    Own properties first, then each prototype in turn, ending at Object.prototype and null.

    Writes always go on the object itself.

  3. 3

  4. 4

In production

Tools and technologies

Classes in JavaScript are built on prototypes.

Not tied to one language — use these names when you search docs or design a system.