Course contentsShow
← JavaScript
Lesson 775 of 2,72318. ClassesFree lesson

The Prototype Chain with Extends

How extends sets up the prototype chain so instanceof and method lookups work.

The Prototype Chain with Extends

You'll learn how extends creates a prototype chain that makes instanceof and method lookups work correctly in class inheritance.

How Extends Wires Up the Chain

When you use extends, JavaScript doesn't just copy methods from parent to child — it connects their prototypes in a chain. This means your child class instances can look up methods and properties through multiple levels, just like you've seen with regular prototype chains.

Here's what extends does behind the scenes:

  1. Instance → Child prototype: Your instance's __proto__ points to ChildClass.prototype
  2. Child prototype → Parent prototype: ChildClass.prototype's __proto__ points to ParentClass.prototype
  3. Parent prototype → Object.prototype: Continues the standard chain
class Animal {
  speak() {
    return "Some sound";
  }
}

class Dog extends Animal {
  bark() {
    return "Woof!";
  }
}

const buddy = new Dog();

// Method lookup walks the chain:
buddy.bark();  // Found on Dog.prototype
buddy.speak(); // Not on Dog.prototype, walks up to Animal.prototype
buddy.toString(); // Walks all the way to Object.prototype

// instanceof checks the entire chain:
console.log(buddy instanceof Dog);    // true
console.log(buddy instanceof Animal); // true (!)
console.log(buddy instanceof Object); // true

Why This Matters

This chain is why instanceof returns true for both the child and parent class — it walks up the prototype chain checking each link. It's also why method lookups work: JavaScript keeps climbing the chain until it finds the property or reaches null.

Key Takeaway: extends creates a prototype chain linking child and parent classes, enabling method inheritance and making instanceof recognize instances as belonging to all classes in the hierarchy.