Created
May 29, 2019 17:46
-
-
Save phenomnomnominal/b904e92a0aa5c9ff44c61323122a4ea9 to your computer and use it in GitHub Desktop.
Example of property and method decorator-like functions
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 PropertyDecorator (propertyOptions) { | |
// Modify the property in some way: | |
return propertyDescriptor; | |
} | |
function MethodDecorator (methodOptions) { | |
// Modify the method in some way: | |
return methodDescriptor; | |
} | |
class MyClass { | |
constructor() { | |
Object.defineProperty(this, 'myProperty', PropertyDecorator({ | |
// ... | |
})); | |
Object.defineProperty(this, 'myMethod', MethodDecorator({ | |
// ... | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment