TypeScript 根据类名的字符串格式来实例化一个新类
目录
1、博客介绍
如题,根据一个字符串来获取固定命名空间下的的一个类,并且实例化他
2、内容
注意:该类必须存在一个固定的命名空间下
/*
*这里写一个在命名空间下的类名
*/
export module manager{
export class TestMgr
{
constructor()
{
super();
}
}
}
/*
*实例方式
*/
var newClass: any = new (<any>manager)["TestMgr "]();
3、推送
Github:https://github.com/KingSun5
4、结语
若是觉得博主的文章写的不错,不妨关注一下博主,点赞一下博文,另博主能力有限,若文中有出现什么错误的地方,欢迎各位评论指摘。
QQ交流群:806091680(Chinar)
该群为CSDN博主Chinar所创,推荐一下!我也在群里!