Skip to content

Instantly share code, notes, and snippets.

@YozhEzhi
Last active January 25, 2017 20:04
Show Gist options
  • Save YozhEzhi/2cba3aa20967f340ffc2 to your computer and use it in GitHub Desktop.
Save YozhEzhi/2cba3aa20967f340ffc2 to your computer and use it in GitHub Desktop.
ES6 composition
const greeter = {
doGreeting(msg) {
console.log(msg);
}
};
const newYearGreeter = {
setYear(year) {
this.year = year;
},
doNewYearGreeting() {
const newYearMsg = `Happy New ${this.year} Year!`;
this.doGreeting(newYearMsg);
}
};
Object.assign(newYearGreeter, greeter);
newYearGreeter.setYear(2017);
newYearGreeter.doNewYearGreeting();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment