Sreejit De
Inheritance in JavaScript: A brief overview
Why is Inheritance useful?
Let's say two objects share a common property, and both objects are of similar type:
As we can see, both the constructors Bus & Bike share a common printWheelCount() property, so we are writing the same code twice by including it in both prototypes separately. There's a way to make this code reusable, and that is where inheritance comes in. Since the classes Bus & Bike are of similar types, we can make a super class Vehicle, and add the common property to the super class. Then, we can inherit the properties of Vehicle inside Bus & Bike. This is how inheritance helps us in following the DRY principle in programming.