Skip to content

Instantly share code, notes, and snippets.

@raynerpupo
Created April 17, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raynerpupo/9f7b5809aadc4070fe6e35ec16f8dcc3 to your computer and use it in GitHub Desktop.
Save raynerpupo/9f7b5809aadc4070fe6e35ec16f8dcc3 to your computer and use it in GitHub Desktop.

Mixins

Mixins favors composition over inheritance by adding some custom behavior to an existing object

const fulfillable = {
  fullfill: (doneFunction) => done("OK")
};

const myObj = {
  quit: () => console.log("quit"),
  ...fulfillable
};

console.log(myObj.quit()); // => quit

myObj.fulfill(console.log); // => OK

In the above example we create a fulfillable object that only have a function property called fulfill. Then, the myObj object that have its own property quit is extended to also have the properties from fulfillable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment