Inheritance with extends in JavaScript
extends builds subclasses inheriting methods and state: class Dog extends Animal gets Animal's interface plus its own additions — the is-a relationship (every Dog works where an Animal is expected). Prototype chains implement it: Dog.prototype delegates to Animal.prototype, so method lookup walks upward.
Prefer composition over deep hierarchies (has-a via fields beats is-a chains past two levels), and remember extends accepts expressions — class X extends Mixin(Base) enables mixin composition patterns.
is-a modeling
class Dog extends Animal — Dog instances answer Animal messages plus Dog's own.
Prototype chains implement
Lookup walks Dog.prototype → Animal.prototype → Object.prototype — delegation, not copying.
Expressions extend too
class X extends factory() — dynamic base classes power mixin patterns (Timestamped(Base)).
Favor shallow trees
Two levels read well; deeper hierarchies tangle — compose behaviors instead of nesting them.
class Animal { constructor(name) { this.name = name; }}class Dog extends Animal { bark() { return this.name + " woofs"; }}console.log(new Dog("Rex").bark());Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.