Доки по разработке
This project is maintained by teniryte
Принципы
Constructor = new (...args: any[]) => {}), чтобы миксин принимал любой класс.scale, setScale).GConstructor накладывайте ограничения: миксин Jumpable работает только с классами, у которых есть setPos.Пример
export class Sprite {
constructor(public name: string, public x = 0, public y = 0) {}
}
function Scale<TBase extends Constructor>(Base: TBase) {
return class Scaling extends Base {
private _scale = 1;
setScale(scale: number) {
this._scale = scale;
}
get scale() {
return this._scale;
}
};
}
type Positionable = GConstructor<{ setPos(x: number, y: number): void }>;
function Jumpable<TBase extends Positionable>(Base: TBase) {
return class extends Base {
jump() {
this.setPos(0, 20);
}
};
}
Практика
Jumpable(Scale(Sprite))).#private поля ES2020.