Last active
February 22, 2016 14:38
-
-
Save thkprado/9ae4ef844d68511a4722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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