Create a gist now

Instantly share code, notes, and snippets.

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)
});
@WebReflection

This comment has been minimized.

Show comment Hide comment
@WebReflection

WebReflection Jan 11, 2016

The original classes based version

Owner

WebReflection commented Jan 11, 2016

The original classes based version

@WebReflection

This comment has been minimized.

Show comment Hide comment
@WebReflection

WebReflection Jan 11, 2016

Example

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

WebReflection commented Jan 11, 2016

Example

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

This comment has been minimized.

Show comment Hide comment
@ialarmedalien

ialarmedalien Feb 3, 2016

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!)

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