如何获取 typescript 中任何对象的构造函数的引用?
JavaScript 中的示例:
var anyObject = new this.constructor(options);
或者
var anyObject = new someObj.constructor(options);
或者
class Greeter {
greeting: string;
constructor(message: string, options: any) {
this.options = options;
this.greeting = message;
} greet() {
return "Hello, " + this.greeting;
} createAnyObj(){
return new this.constructor(this.options);
}
}
var t= new Greeter('mes',{param1: 'val1'});
var b=t.createAnyObj();
谢谢。
更多示例: