Skip to content

Instantly share code, notes, and snippets.

@hwclass
Last active May 24, 2016 13:04
Show Gist options
  • Save hwclass/69b306b7436c92ba397b57cb84c89389 to your computer and use it in GitHub Desktop.
Save hwclass/69b306b7436c92ba397b57cb84c89389 to your computer and use it in GitHub Desktop.
//Composition builder wrapper
const Builder = (() => {
compose = (obj, props) => {
return Object.assign(obj, props)
}
return {
compose: compose
}
})();
//test object
let testObj = {};
//functionality as mixin
const mixin= {
drive: () => {
console.log('driving...')
}
};
//building a new object with functionality
const driver = Builder.compose(testObj, mixin);
//drive the car
driver.drive(); //logs driving...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment