首页 > 解决方案 > 在装饰器中获取原始方法的文件路径?

问题描述

我正在寻找一种方法来获取我的原始函数在它的装饰器中的文件路径,而不通过函数参数传递它,该函数参数位于不同的(一些常见的)目录中,因为这个装饰器用于许多其他功能。任何想法?谢谢!

// 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
}

标签: javascriptnode.jstypescript

解决方案


推荐阅读