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
| class Athlete { | |
| constructor(private name: string) {} | |
| } | |
| const MixinDecathlete = ThrowsFar(RunsFast(JumpsHigh(Athlete))); | |
| const mixinDecathlete = new MixinDecathlete('Rafer Johnson'); | |
| mixinDecathlete.runFast(); | |
| mixinDecathlete.throwFar(); | |
| mixinDecathlete.jumpHigh(); |
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
| function RunsFast<TBase extends Constructor>(Base: TBase) { | |
| return class extends Base { | |
| runFast() { | |
| console.log('Runs fast'); | |
| } | |
| }; | |
| } | |
| function ThrowsFar<TBase extends Constructor>(Base: TBase) { | |
| return class extends Base { |
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
| type Constructor<T = {}> = new (...args: any[]) => T; |
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
| class Decathlete implements RunsFast, JumpsHigh, ThrowsFar { | |
| runsFast!: () => void; | |
| jumpsHigh!: () => void; | |
| throwsFar!: () => void; | |
| } |
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
| const aDecathlete = new Decathlete(); | |
| console.log('Decathlete:'); | |
| aDecathlete.runsFast(); | |
| aDecathlete.jumpsHigh(); | |
| aDecathlete.throwsFar(); |
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
| applyMixins(Decathlete, [runsFast, jumpsHigh, throwsFar]); |
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
| class Decathlete implements runsFast, jumpsHigh, throwsFar { | |
| runsFast: () => void; | |
| jumpsHigh: () => void; | |
| throwsFar: () => void; | |
| } |
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
| function applyMixins(derivedCtor: any, baseCtors: any[]) { | |
| baseCtors.forEach(baseCtor => { | |
| Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { | |
| derivedCtor.prototype[name] = baseCtor.prototype[name]; | |
| }); | |
| }); |
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
| class runsFast { | |
| runsFast() { | |
| console.log('Runs fast'); | |
| } | |
| } | |
| class jumpsHigh { | |
| jumpsHigh() { | |
| console.log('Jumps high'); | |
| } |
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
| function EncryptSomething(aSuperSecretStuff: any[], aIWantToBeSafe: Boolean) { | |
| var encryptor: IEncrypt; | |
| if (aIWantToBeSafe) { | |
| encryptor = new superDuperPowerfulEncryption(); | |
| } else { | |
| encryptor = new whoCaresHowSafe(); | |
| } | |
| encryptor.Encrypt(aSuperSecretStuff); | |
| } |
NewerOlder