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