UNPKG

ziko

Version:

a versatile javaScript framework offering a rich set of UI components, advanced mathematical utilities, reactivity, animations, client side routing and graphics capabilities

29 lines (23 loc) 770 B
export function composeClass(Class, mixin) { const descriptors = Object.getOwnPropertyDescriptors(mixin); class Composed extends Class { constructor(...args) { super(...args); for (const key of Reflect.ownKeys(descriptors)) { const desc = descriptors[key]; if (typeof desc.value === 'function') { this[key] = desc.value.bind(this); } } } } for (const key of Reflect.ownKeys(descriptors)) { const desc = descriptors[key]; if ('get' in desc || 'set' in desc) { Object.defineProperty(Composed.prototype, key, desc); } else if (typeof desc.value !== 'function') { Object.defineProperty(Composed.prototype, key, desc); } } return Composed; }