Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Created May 29, 2019 17:46
Show Gist options
  • Save phenomnomnominal/b904e92a0aa5c9ff44c61323122a4ea9 to your computer and use it in GitHub Desktop.
Save phenomnomnominal/b904e92a0aa5c9ff44c61323122a4ea9 to your computer and use it in GitHub Desktop.
Example of property and method decorator-like functions
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