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
thisis separate from where a method is foundinstanceofchecks prototype relationships- Prototype mutation affects all delegating objects
const animal = {
speak() {
return `${this.name} makes noise`
},
}
const dog = Object.create(animal)
dog.name = "Milo"
dog.speak() // "Milo makes noise"