-
-
Save allanphilipbarku/d85f5f833d2d70f916297c39dd587611 to your computer and use it in GitHub Desktop.
Car class in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car { | |
constructor(make, model) { | |
this.make = make; | |
this.model = model; | |
} | |
start() { | |
console.log('vroom'); | |
} | |
toString() { | |
console.log(`Car - ${this.make} - ${this.model}`); | |
} | |
} | |
class SportsCar extends Car { | |
constructor(make, model, turbocharged) { | |
super(make, model); | |
this.turbocharged = turbocharged; | |
} | |
start() { | |
console.log('VROOOOM'); | |
} | |
} | |
// Actual usage remains the same | |
var car = new Car('Nissan', 'Sunny'); | |
car.start(); // vroom | |
console.log(car.make); // Nissan | |
var sportsCar = new SportsCar('Subaru', 'BRZ', true); | |
sportsCar.start(); // VROOOOM | |
console.log(car.turbocharged); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment