0

I am looking for a way to get the file path of my original function inside it's decorator without passing it by a function parameter, which is located in a different (some common) directory, since this decorator is used for many other functions. Any idea? Thanks!

// decorator in a different folder
export const SomeDecoratorFunction = () => (target, key, descriptor) => {
  const originalFunction = descriptor.value;

  descriptor.value = function (this) {

    // Get file path of originalFunction

    return originalFunction.apply(this, arguments);
  };

  return descriptor;
};
// original function
@SomeDecoratorFunction()
public async someFunction(req: Request, res: Response): Promise<void> {
  // some code
}
x2p
  • 27
  • 6
  • "*without passing it by a function parameter*" - not really possible. Why don't you want to use a parameter? You already have a function you call anyway. – Bergi Jun 12 '21 at 11:01
  • If it's not possible I gonna use a parameter. – x2p Jun 12 '21 at 13:57
  • https://stackoverflow.com/questions/41146373/access-function-location-programmatically – Bergi Jun 30 '22 at 14:49

0 Answers0