11
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屬性?
冠軍!對不起,沒有足夠的信譽+1 –
@AlexVaghin你可以/應該標記爲答案 – basarat