Last active
October 5, 2020 10:00
-
-
Save disco0/b0fe5af952d96371f4b315eeb381ae95 to your computer and use it in GitHub Desktop.
TypeScript - Mixin Class
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; | |
//#region Mixins | |
// A mixin that adds a property | |
function Timestampable<TBase extends Constructor>(Base: TBase) | |
{ | |
return class extends Base | |
{ | |
timestamp = Date.now(); | |
}; | |
} | |
// a mixin that adds a property and methods | |
function Activatable<TBase extends Constructor>(Base: TBase) | |
{ | |
return class extends Base | |
{ | |
isActivated = false; | |
activate() | |
{ | |
this.isActivated = true; | |
} | |
deactivate() | |
{ | |
this.isActivated = false; | |
} | |
}; | |
} | |
//#endregion Mixins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment