课程: JavaScript: Five Advanced Challenges and Concepts
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Creating a class with capabilities - JavaScript教程
课程: JavaScript: Five Advanced Challenges and Concepts
Creating a class with capabilities
- [Instructor] Let's set up a basic object inheritance structure using classes. In this example, I'll use Vehicle as my main class and extend it with two specific types of vehicles, Car and Bike. You'll notice in the setup code here that when I set up new Car, I have the name of the car and the number of doors, and when I set up new Bike, I have the name of the bike and the type of bike. So these two subclasses have different properties that we need to capture, and those different properties are output differently. So we have, "My car has four wheels and four doors," or, "My bike has two wheels and is an off-road type," off-road type bike. So, I need to figure out how to manage the different types and the different outputs using the same method, this getDescription method. We'll start off by creating the Vehicle class. So here I'll say constructor. Then in the constructor, I want to capture the properties that are…