Skip to content

Instantly share code, notes, and snippets.

@kironroy
Created July 25, 2023 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kironroy/0bc5449cf047736fb118ac4c517e085d to your computer and use it in GitHub Desktop.
Save kironroy/0bc5449cf047736fb118ac4c517e085d to your computer and use it in GitHub Desktop.
Constructors example
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