Created
October 25, 2019 02:57
-
-
Save clementohNZ/f4c05e74759ea92af9ca102e12b85a7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
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