Last active
March 27, 2021 18:38
-
-
Save WebReflection/37e5aa408c8ac69a0fdd to your computer and use it in GitHub Desktop.
"Real" Mixins with JavaScript Objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mix = (object) => ({ | |
with: (...mixins) => mixins.reduce( | |
(c, mixin) => Object.create( | |
c, Object.getOwnPropertyDescriptors(mixin) | |
), object) | |
}); |
Example
let a = {a: 'a'};
let b = {b: 'b'};
let c = {c: 'c'};
let d = mix(c).with(a, b);
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
The original classes based version