Solution Review: ES6 Inheritance
Explore how to implement ES6 inheritance in JavaScript by creating a Vehicle class and extending it with a Car class. Learn to use constructors, super to call parent methods, and override functions with conditional logic to control behavior based on class properties.
We'll cover the following...
We'll cover the following...
Solution #
Explanation #
Let’s start by discussing the implementation of the Vehicle class first.
-
On line 2, we are defining the
constructor. It initializes thefuelproperty by setting it equal to the parameter passed.constructor(fuel) { this.fuel = fuel; } -
On line 3, we are implementing the
turnOnfunction. It displays the messageTurned on.