首页 > 解决方案 > ES6 反射中的 Type.GetType 等效项

问题描述

我最近读到了 ES6(符号、反射、代理)的元编程改进,它们确实很酷,但是我很难找到如何在 Type.GetType(细绳)。

ES6 中是否有等效选项?

背景是,如果我想使用反射来调用类的构造函数,我也希望以编程方式拥有该类型。

function commandFactory(name : string, args : CommandArgs) : Command {
  let commandType = Type.GetType(name); /* theoretically speaking*/
  return Reflect.construct(commandType, [args]);
}

提前致谢!

标签: javascriptreflectionecmascript-6

解决方案


推荐阅读