let map:Map<string,any> = new Map();

abstract class A{
protected _x:number = 2;
    static register(){
        map.set(this.name,this);//this:当前类(非对象)
    }
}

class B extends A{

}

class C extends B{
constructor(){
super();
this._x = 3;
}
print(){
console.log(this._x);
}
}

C.register();
map.forEach((each,index)=>{
console.log(new each());
})

运行时获得类名+通过instance和class来获得

2019-02-18 00:13:04 0 62
这里是评论

相关推荐