forked from TrainingByPackt/Professional-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise49.js
More file actions
42 lines (38 loc) · 985 Bytes
/
Copy pathExercise49.js
File metadata and controls
42 lines (38 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Vehicle {
constructor(name, speed, cost) {
this.name = name;
this.speed = speed;
this.cost = cost;
}
start() {
console.log('Starting vehicle, ' + this.name + ' at ' + this.speed + 'km/h');
}
buy() {
console.log('Buying for ' + this.cost);
}
}
function printStat() {
console.log('The car has a tanksize of ', this.tankSize);
}
class Car extends Vehicle {
constructor(name, speed, cost, tankSize) {
super(name, speed, cost);
this.tankSize = tankSize;
}
start() {
console.log('Driving car, at ' + this.speed + 'km/h');
printStat.bind(this)();
}
}
class Plane extends Vehicle {
start() {
console.log('Flying plane, at ' + this.speed + 'km/h');
}
}
class Rocket extends Vehicle {
start() {
console.log('Flying rocket to the moon, at ' + this.speed + 'km/h');
}
}
const car = new Car('Toyota Corolla', 120, 5000, 2000);
car.start();