Skip to content

Inheritance

Inheritance in JavaScript is prototypal — objects inherit from other objects. This is fundamentally different from classical inheritance in languages like Java or C++.

  • Understand prototypal vs classical inheritance
  • Use constructor functions for inheritance
  • Use ES6 class syntax with extends
  • Understand composition as an alternative
  • Know when to use inheritance vs composition
flowchart TD
A["Animal: eat(), sleep()"]
B["Dog: bark()"]
C["Cat: meow()"]
A --> B
A --> C
D["Dog instance: Rex"]
E["Cat instance: Whiskers"]
B --> D
C --> E
TopicDescriptionEst. Time
Prototypal InheritanceClassical-style using constructor functions20 min
Class Inheritanceextends, super, method overriding15 min
Composition vs InheritanceFavor composition over inheritance15 min
  • Prototypes and the prototype chain
  • Constructor functions
  • ES6 class syntax
Prototypal Inheritance → Class Inheritance → Composition vs Inheritance