TypeScript instantiates a new class according to the string format of the class name

                   TypeScript instantiates a new class based on the string format of the class name


table of Contents

1. Blog introduction

2. Content

3. Push

4. Conclusion


1. Blog introduction

As the title, according to a string to obtain a class under a fixed namespace, and instantiate him


2. Content

Note : This class must exist under a fixed namespace

 

/*
 *这里写一个在命名空间下的类名
 */
export module manager{

    export class TestMgr 
    {
        constructor()
        {
            super();
        }
    }

}


/*
 *实例方式
 */
var newClass: any = new (<any>manager)["TestMgr "]();


3. Push

Github:https://github.com/KingSun5


4. Conclusion


       If you feel that the blogger’s article is well written, you may wish to pay attention to the blogger and like the blog post. In addition, the ability of the blogger is limited. If there is any error in the article, you are welcome to comment and criticize.

       QQ exchange group: 806091680 (Chinar)

       This group was created by CSDN blogger Chinar, recommend it! I am also in the group!

Guess you like

Origin blog.csdn.net/Mr_Sun88/article/details/102594818
Recommended