/* ==== ECMAScript 6 variant ==== */ export default (base, ...mixins) => { /* create aggregation class */ const merge = class __Merge extends base { constructor (...args) { /* call base class constructor */ super(...args) /* call mixin's initializer */ mixins.forEach((mixin) => { if (typeof mixin.prototype.initializer === 'function') mixin.prototype.initializer.apply(this, args) }) } } /* copy properties */ let copyProps = (target, source) => { Reflect.ownKeys(source) .forEach((prop) => { if (typeof prop.match ==='function') { if (prop.match(/^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)) return } Reflect.set(target,prop,Reflect.getOwnPropertyDescriptor(source, prop)) }) } /* copy all properties of all mixins into aggregation class */ mixins.forEach((mixin) => { copyProps(merge.prototype, mixin.prototype) copyProps(merge, mixin) }) return merge }