【发布时间】:2013-10-17 17:10:16
【问题描述】:
有人建议使用这样的代码
class A {
// Setting this to private will cause class B to have a compile error
public x: string = 'a';
}
class B extends A {
constructor(){super();}
method():string {
return super.x;
}
}
var b:B = new B();
alert(b.method());
它甚至获得了 9 票。但是当你粘贴到官方的TS游乐场时 http://www.typescriptlang.org/Playground/ 它给你和错误。
如何从 B 访问 A 的 x 属性?
【问题讨论】:
标签: inheritance properties typescript superclass