Created
July 25, 2023 21:59
-
-
Save kironroy/0bc5449cf047736fb118ac4c517e085d to your computer and use it in GitHub Desktop.
Constructors example
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
const Car = function(make, speed) { | |
this.make = make; | |
this.speed = speed; | |
} | |
Car.prototype.accelerate = function () { | |
console.log(`${this.make} is accelerating at ${this.speed + 10} m/hr`); | |
}; | |
Car.prototype.brake = function () { | |
console.log(`${this.make} is de-accelerating at ${this.speed - 5} m/hr`); | |
} | |
const mazda = new Car('Mazda', 120); | |
const ford = new Car('Ford', 95); | |
mazda.accelerate(); | |
mazda.brake(); | |
ford.accelerate(); | |
ford.brake(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment