Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created September 17, 2021 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapkub/98b28c2a82f552ff119ab1941bbfbcf3 to your computer and use it in GitHub Desktop.
Save zapkub/98b28c2a82f552ff119ab1941bbfbcf3 to your computer and use it in GitHub Desktop.
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