为什么我做不到这一点?这是由于Javascript/Typescript的技术限制,还是由Typescript开发人员做出的设计决策?相同的代码在Java或C#中可以正常工作。
class Test {
static str: string = "test";
public static getTest(): string {
return this.str;
}
}
//works as expected
console.log(Test.getTest());
//won't compile
var test: Test = new Test();
console.log(test.getTest());