Created
January 12, 2020 17:23
-
-
Save r3dm1ke/45025f5ff6bebad27005b7dcd46f1967 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