Skip to content

Instantly share code, notes, and snippets.

@thkprado
Last active February 22, 2016 14:38
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 thkprado/9ae4ef844d68511a4722 to your computer and use it in GitHub Desktop.
Save thkprado/9ae4ef844d68511a4722 to your computer and use it in GitHub Desktop.
const food = {
init: function(type) {
this.type = type
},
eat: function() {
console.log('you ate the ' + this.type)
},
create: function(type) {
const o = Object.create(food)
o.init(type)
return o
}
}
const waffle = Object.create(food)
waffle.init('waffle')
const banana = food.create('banana')
console.log('waffle is food?', food.isPrototypeOf(waffle))
console.log('banana is food?', food.isPrototypeOf(banana))
waffle.eat()
banana.eat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment