Created
November 16, 2016 15:31
-
-
Save awerlang/590dccc22ac8f00b00b8ca782fa1a51c to your computer and use it in GitHub Desktop.
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
/** | |
Mixes in objects in `properties` into a class. | |
To be used as a decorator. | |
@mixin({...}) | |
class MyClass {...} | |
*/ | |
function mixin(properties: {[key: string]: any}): Function { | |
if (properties == null) { | |
throw new Error(`Argument for 'properties' is required.`); | |
} | |
return function (target: any): any { | |
if (typeof properties === 'object') { | |
Object.keys(properties).forEach(name => { | |
target.prototype[name] = properties[name]; | |
}); | |
} | |
return target; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment