Created
September 17, 2021 08:18
-
-
Save zapkub/98b28c2a82f552ff119ab1941bbfbcf3 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
export const Badthing = (): MethodDecorator => { | |
return ( | |
target: Object, | |
key: string | symbol, | |
descriptor: PropertyDescriptor, | |
) => { | |
const originalMethod = descriptor.value; | |
console.log("Badthing"); | |
descriptor.value = (...args: any[]) => { | |
args[0] = 'I do not ' + args[0]; | |
return originalMethod.apply(this, args); | |
}; | |
return descriptor; | |
}; | |
}; | |
class SomethingNice { | |
@Badthing() | |
public doGoodThings(task?: string) { | |
console.log(task); | |
} | |
} | |
const x = new SomethingNice(); | |
x.doGoodThings("Wash dishes"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment