You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/util/support/mixin.ts

21 lines
658 B

/**
* Apply the given mixin classes to the given constructor.
* @param derivedCtor
* @param {array} baseCtors
*/
export function applyMixins(derivedCtor: FunctionConstructor, baseCtors: any[]): void {
baseCtors.forEach(baseCtor => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
const desc = Object.getOwnPropertyDescriptor(baseCtor.prototype, name)
if ( typeof desc !== 'undefined' ) {
Object.defineProperty(derivedCtor.prototype, name, desc)
}
})
})
}
/**
* Base type for a constructor function.
*/
export type Constructor<T> = new (...args: any[]) => T