Created
July 20, 2016 09:19
-
-
Save vasergen/869d1181ff352058a3417ba188bfa321 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Function composition | |
function Animal(name) { | |
let publicAPI = { | |
say: function() { | |
console.log(`I am ${name}`); | |
} | |
} | |
return publicAPI | |
} | |
function Rabbit(name) { | |
let animalPublicAPI = new Animal(name) | |
let publicAPI = { | |
skip: function() { | |
console.log(name + ': I skip'); | |
} | |
} | |
return Object.assign(publicAPI, animalPublicAPI) | |
} | |
let r1 = Rabbit('r1') | |
r1.say() | |
r1.skip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment