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
.