JavaScript Runtime Semantics

Prototype Chain & Inheritance

JavaScript object inheritance is prototype-based. When a property is not found on an object, lookup continues through the object's prototype chain until the property is found or the chain ends at null.
  • The prototype chain is delegation
  • Class methods live on the prototype
  • this is separate from where a method is found
  • instanceof checks prototype relationships
  • Prototype mutation affects all delegating objects
Delegation example
const animal = {
  speak() {
    return `${this.name} makes noise`
  },
}

const dog = Object.create(animal)
dog.name = "Milo"

dog.speak() // "Milo makes noise"
The method is found on `animal`; `this` is still `dog` because of the call expression.
Sources
  • MDN JavaScript Guide and ReferenceInheritance and the prototype chain
  • You Don’t Know JS YetObjects and Classes
  • ECMAScript Language SpecificationOrdinary object internal methods