Skip to content

Instantly share code, notes, and snippets.

@clementohNZ
Created October 25, 2019 02:57
Show Gist options
  • Save clementohNZ/f4c05e74759ea92af9ca102e12b85a7f to your computer and use it in GitHub Desktop.
Save clementohNZ/f4c05e74759ea92af9ca102e12b85a7f to your computer and use it in GitHub Desktop.
class Car {
constructor() {
this.distance = 0;
}
move() {
this.distance += 1;
console.log(`current distance is: ${this.distance}`);
}
}
class Toyota extends Car {
constructor() {
super();
}
move() {
super.move();
}
}
class Ferrari extends Car {
constructor() {
super();
}
moveVeryQuickly() {
this.distance += 5;
console.log(`current distance is: ${this.distance}`);
}
}
const cars = [
new Car(),
new Toyota(),
new Ferrari(),
]
cars.forEach(car => {
car.move();
});
// current distance is: 1
// current distance is: 1
// current distance is: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment