Created
January 6, 2022 19:58
-
-
Save GokselKUCUKSAHIN/e587032a30298869a3b79aed3863da1e to your computer and use it in GitHub Desktop.
TypeScript Multiple Inheritance using Mixins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {using, Disposable} from "using-statement"; | |
import {Mixin} from "ts-mixer"; | |
import {EventEmitter} from "events"; | |
class Walker { | |
walk() { | |
console.log("walking..."); | |
} | |
} | |
class Jumper { | |
jump() { | |
console.log("jumping..."); | |
} | |
} | |
// extending 3 Class | |
class MyComplexClass extends Mixin(EventEmitter, Walker, Jumper) implements Disposable { | |
private readonly _name: string; | |
constructor(name = "n/A") { | |
super(); | |
this._name = name; | |
} | |
get name(): string { | |
return this._name; | |
} | |
dispose(): void { | |
console.log("disposed."); | |
} | |
} | |
using(new MyComplexClass("sqrt(-1)"), complex => { | |
console.log(complex.name); | |
complex.jump(); | |
complex.walk(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment