Prototypes and Object.create
by Eugene Manager
JavaScript
//https://www.youtube.com/watch?v=riDVvXZ_Kb4
const food = {
init: function(type) {
this.type = type
},
eat: function() {
console.log('you ate the ' + this.type)
}
}
const waffle = Object.create(food);
const carrot = Object.create(food);
// prooving that food is a prototype for a waffle and carrot
food.eat = function() {
console.log('YOU ATE THE ' + this.type)
}
waffle.init("waffle")
carrot.init("carrot")
waffle.eat();
carrot.eat();