fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
23 lines (21 loc) • 673 B
text/typescript
import type { Constructor } from '../typedefs';
/***
* https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
*/
export function applyMixins<T extends Constructor, S extends Constructor>(
derivedCtor: T,
constructors: S[],
) {
constructors.forEach((baseCtor) => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
name !== 'constructor' &&
Object.defineProperty(
derivedCtor.prototype,
name,
Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
Object.create(null),
);
});
});
return derivedCtor as T & { prototype: InstanceType<T & S> };
}