Skip to content

Instantly share code, notes, and snippets.

Last active March 27, 2021 18:38
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
"Real" Mixins with JavaScript Objects
let mix = (object) => ({
with: (...mixins) => mixins.reduce(
(c, mixin) => Object.create(
c, Object.getOwnPropertyDescriptors(mixin)
), object)
Copy link

The original classes based version

Copy link


let a = {a: 'a'};
let b = {b: 'b'};
let c = {c: 'c'};
let d = mix(c).with(a, b);

Copy link

Would you consider working this up into a tested/released version with full class support? (I know it's pretty short, but so is the original code!)

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