Max*_*lid 2 javascript class typescript
我试图开始某种工作:
export class SomeComponent {
constructor() {
let className: string = "TheClass";
/* should be the same as .. = new TheClass() */
let superSpecial = new className();
}
}
Run Code Online (Sandbox Code Playgroud)
我还没有弄清楚该怎么做?有人可以帮我吗?
有几种方法可以做到这一点。如果您的课程在单独的模块中:
SomeClass.ts
export class SomeClass {
constructor(arg: string) {
console.log(arg);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程式
import * as s from "./SomeClass";
var instance = new s["SomeClass"]("param");
Run Code Online (Sandbox Code Playgroud)
或使用名称空间:
namespace Test {
export class SomeClass {
constructor(arg: string) {
console.log(arg);
}
}
}
var instance = new Test["SomeClass"]("param");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8020 次 |
| 最近记录: |