Glossary / Prototype chain

Prototype chain

The prototype chain is the sequence of objects JavaScript consults when a property is not found directly on an object. Each ordinary object has an internal [[Prototype]] link; lookup follows those links until it finds a property or reaches null. This delegation mechanism underlies method inheritance, class instances, and many built-in behaviors.

Lookup, shadowing, and mutation

const base = { kind: "base", describe() { return this.kind; } };
const child = Object.create(base);
child.kind = "child";
child.describe(); // "child": inherited method uses child as this

child.describe is found on base, but the call receiver is child; the inherited method uses the child’s kind. An own property shadows an inherited property without changing the prototype. Assignment usually creates or updates an own property; it does not mutate the prototype’s data property.

Use Object.getPrototypeOf and Object.setPrototypeOf for explicit reflection (but generally avoid changing prototypes after object creation). Object.create(null) creates a dictionary with no inherited Object methods. The legacy __proto__ accessor is not recommended for ordinary code. Prototype mutation can affect every inheriting object and complicate performance and security reasoning.

Prototype lookup is distinct from lexical variable lookup. Also distinguish an instance’s [[Prototype]] from a constructor function’s public prototype property: the latter is the object new instances normally link to.

Interview questions

  1. Where does lookup go when an own property is absent? Up the object’s prototype chain.
  2. What is shadowing? An own property hides an inherited property with the same key.
  3. How inspect an object's prototype? Object.getPrototypeOf(obj).
  4. Why avoid prototype mutation? It changes behavior across inheritors and harms predictability, security, and optimization.

References