---
title: "The live prototype chain"
url: "https://www.mikefluff.com/en/experiments/js-ch02-proto-chain"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-18"
description: "The JavaScript prototype chain"
book: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
alternates:
  - locale: "en"
    url: "https://www.mikefluff.com/en/experiments/js-ch02-proto-chain"
    markdown: "https://www.mikefluff.com/en/experiments/js-ch02-proto-chain.md"
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/experiments/js-ch02-proto-chain"
    markdown: "https://www.mikefluff.com/ru/experiments/js-ch02-proto-chain.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/experiments/js-ch02-proto-chain"
    markdown: "https://www.mikefluff.com/pt/experiments/js-ch02-proto-chain.md"
  - locale: "es"
    url: "https://www.mikefluff.com/es/experiments/js-ch02-proto-chain"
    markdown: "https://www.mikefluff.com/es/experiments/js-ch02-proto-chain.md"
---

# The live prototype chain

*The JavaScript prototype chain*

## What is the prototype chain in JavaScript?

Every JavaScript object has an internal link to another object, its prototype, and that object has a prototype of its own, up to Object.prototype, whose prototype is null. This sequence is the prototype chain. Reading a property starts on the object itself; if the name is not there, the lookup moves to the prototype, and so on until the name is found or the chain ends in null, and then the result is undefined. Writing a property normally creates it on the object itself. Because objects share their prototype by reference, a method added to a prototype is visible at once to every object that inherits from it, including objects created before the change.

JavaScript took delegation from Self. An object has no class in the Java sense; it has a prototype, and the author of a program decides where a method lives and may change their mind at any moment, for built-in objects too. In the mid-2000s Prototype.js and MooTools added methods to the built-in prototypes, and in 2018 that old habit cost the language the name flatten.

The first tab holds three real objects, a, b and c, made with Object.create(P). Type or pick a property name and press Look up: the read checks the object, then P, then Object.prototype, and stops at the first level that has the name or at null. Add a method to P and all three objects get it at once, although they were created before it. Give c another prototype with Object.setPrototypeOf and it stops seeing the method. The second tab runs the book’s proto.js in your browser: o.get() on a million objects whose method sits on the prototype, with the prototype left alone, patched with a new property before every measurement, or swapped for one object in a million.

In the book, on Node 24 and an M4 Max, the median of 50 measurements was 1.00–1.21 ms with the prototype left alone, 1.85–2.95 ms when it was patched before each measurement and 1.54–1.60 ms when one object got another prototype. The deoptimisation log showed 100 deoptimisations over 50 patched measurements, two per change, all with the reason dependent prototype chain changed; the swap caused three of those and one wrong map. A page cannot see deoptimisations, so the counts beside your numbers are the book’s.

This is the chapter’s argument in miniature. The specification gives the author the right to change a prototype whenever they like, and the engine cannot forbid it. It can only bet that the chain stays put, check the bet and throw away its optimised code when it loses, while the program still gets the right answer.

_The page has an interactive experiment that runs in a browser: https://www.mikefluff.com/en/experiments/js-ch02-proto-chain_

## Sources

- [MDN, Inheritance and the prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)
- [Chrome for Developers, SmooshGate FAQ (2018)](https://developer.chrome.com/blog/smooshgate)

## From the book

Beside it in the book:

> In this chapter a new participant has joined the conversation about responsibility. An open built-in prototype makes any popular library a co-author of the standard library, and the consequences are then cleaned up by the standards committee, the browser vendors and everyone who will be writing code ten years from now. That kind of responsibility cannot be handed back: the name flatten on arrays is taken forever, although hardly anyone includes MooTools anymore.

- Read the chapter: [Chapter 2. Objects Without Classes](https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch02) (opening free, rest in the full book; Markdown: https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch02.md)

- Book: [JavaScript: From Closures to Autonomous Systems](https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems)
