Created
March 27, 2016 16:33
-
-
Save raduGaspar/5165881947eab29a7eab 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 swimmer = (state) => ({ | |
swim: () => console.log(state.name, 'is swimming') | |
}) | |
const eater = (state) => ({ | |
eat: () => console.log(state.name, 'is eating') | |
}) | |
const sleeper = (state) => ({ | |
sleep: () => console.log(state.name, 'is sleeping') | |
}) | |
const flyer = (state) => ({ | |
fly: () => console.log(state.name, 'is flying') | |
}) | |
const clucker = (state) => ({ | |
cluck: () => console.log(state.name, 'is clucking') | |
}) | |
const quacker = (state) => ({ | |
quack: () => console.log(state.name, 'is quacking') | |
}) | |
const Duck = (name) => { | |
let state = { | |
name | |
}; | |
return Object.assign( | |
{}, | |
swimmer(state), | |
eater(state), | |
sleeper(state), | |
flyer(state), | |
quacker(state) | |
); | |
} | |
const RubberDuck = (name) => { | |
let state = { | |
name | |
}; | |
return Object.assign( | |
{}, | |
swimmer(state), | |
quacker(state) | |
); | |
} | |
Duck('SirQuack').quack(); | |
RubberDuck('Ducky').swim(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment