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 - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Enhancing object literals2m 8s
-
(Locked)
Creating objects with the spread operator1m 25s
-
(Locked)
Destructuring objects3m 2s
-
(Locked)
Iterating with the for/of loop2m 40s
-
(Locked)
Introducing classes2m 28s
-
(Locked)
Inheritance with JavaScript classes1m 39s
-
(Locked)
Getting and setting class values3m 35s
-
(Locked)
-
-
-