const beverage = {
init({name}) {
this.name = name
if (this.checkIfProcessComplete()) {
this.makeDrink()
} else {
console.log(`You have missed some steps for your ${this.name}. Please check again.`)
}
},
makeDrink() {
this.boilWater()
this.brew()
this.pourInCup()
this.addCordiments()
},
checkIfProcessComplete() {
return (this.boilWater && this.brew && this.pourInCup && this.addCordiments)
}
}
const coffee = Object.create(beverage)
coffee.boilWater = function() {
console.log(`boil water for ${this.name}`)
}
coffee.brew = function() {
console.log(`brew for ${this.name}`)
}
coffee.pourInCup = function() {
console.log(`pour in cup for ${this.name}`)
}
coffee.addCordiments = function() {
console.log(`add cordiments for ${this.name}`)
}
const tea = Object.create(beverage)
tea.boilWater = function() {
console.log(`boil water for ${this.name}`)
}
tea.brew = function() {
console.log(`brew for ${this.name}`)
}
tea.pourInCup = function() {
console.log(`pour in cup for ${this.name}`)
}
tea.addCordiments = function() {
console.log(`add cordiments for ${this.name}`)
}
const espresso = Object.create(coffee)
const herbals = Object.create(tea)
espresso.init({name: 'good espresso'})
herbals.init({name: 'black tea'})