node.js - 装饰器 - 在子函数中读取标识符
问题描述
每次调用装饰器时,我都会创建一个需要在子函数中读取的标识符,我该怎么做?
例子
import { v4 as uuidv4 } from 'uuid';
export const DecoratorTest = (): MethodDecorator => {
return (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => {
const method = descriptor.value;
descriptor.value = async function (...args: any[]) {
let identifier = uuidv4(); // Identifier I want to read in child function
return await method.apply(this, args);
};
return descriptor;
};
};
我在 func1 调用装饰器
@DecoratorTest()
function func1(param1: number, param2: number) {
func2(param1, param2);
}
如何获得在装饰器中创建的标识符?
function func2(param1: number, param2: number) {
// READ identifier decorator
}
解决方案
推荐阅读
- python - 如何通过使用 python 给出条件来自动复制文件?
- javascript - 如何使用 React 显示图像上传预览?
- algorithm - 与选择和排名进行最佳匹配的算法
- php - 使用 XMLReader 查找节点并从当前节点和后续子节点检索 XML
- typescript - 打字稿函数重载:无法访问的“this”类型
- javascript - JavaScript 类 构造函数 用作附加到 HTML 文件的变量
- shell - 将扩展名添加到 bluespice docker 映像
- c# - C# IQueryable 在一个组 new 之后连接两个字段
- selenium - 我需要使用工具提示阅读文本,我尝试了很多方法,但我总是得到我找不到那个元素的结果(selenium-java)
- wordpress - 如何选择一个 Wordpress 页面作为自定义帖子类型存档