Inheritance in JavaScript
Implement inheritance patterns
AdvancedAdvanced JSExample 2 of 12
inheritance.js
1class Animal {2 constructor(name) { this.name = name; }3 speak() { return this.name + ' makes a sound'; }4}5class Dog extends Animal {6 speak() { return this.name + ' barks'; }7}
Output
// Inheritance example
What's going on
Inheritance enables code reuse through classes.