From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Inheritance with JavaScript classes

Inheritance with JavaScript classes - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Inheritance with JavaScript classes

- [Tutor] In the previous video, we created a Vehicle class, and now I'm going to create a new class that will inherit from the Vehicle class. And this is a process called extending the class, which means that I can take a vehicle which could be any kind of vehicle, a car, a truck, a bicycle, and extend it to customize it for a specific type of vehicle. So the type I'm going to create is a SemiTruck. Now inside of the constructor, we're going to pass in a couple of values for description and wheels, and we're going to pass these via a function called super. So super is going to go up to the Vehicle and it's going to plug in SemiTruck for the descriptor and 18 for the number of wheels. When I want to create a new instance of the SemiTruck, I'll do it here on line 20, I'll just create a variable and I'll set it equal to a new SemiTruck. And now I can use the describeYourself function to actually log that message. So…

Contents