Prototype Chain

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Prototype Chain

Approach

Set up prototypal inheritance by creating a Dog constructor that calls Animal via Animal.call(this, name), then links prototypes with Object.create(Animal.prototype). This establishes the prototype chain so Dog instances inherit Animal methods while adding their own.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Prototype Chain

Why It Works

JavaScript property lookup walks the prototype chain. When dog.speak() is called, the engine checks dog, then Dog.prototype, then Animal.prototype, finding the method there.

Updated Feb 2026