Javascript : Class
Overview
Class was added in ES6. It is using prototype JS under the hood.
ES6 Javascript
class CoffeeMaker {
Constructor(grinder, pump, heater) {
this.grinder = grinder;
this.pump = pump;
this.heater = heater;
}
brew () {
console.log("Brewing coffee");
this.grinder.grind();
this.heater.on();
this.pump.pump();
}
}
Prototype Javascript
var CoffeeMaker = function(grinder, pump, heater) {
this.grinder = grinder;
this.pump = pump;
this.heater = heater;
}
CoffeeMaker.prototype.brew = function () {
console.log("Brewing coffee");
this.grinder.grind();
this.heater.on();
this.pump.pump();
}