Fen*_*ton 49
2014年11月12日.TypeScript 1.3版可用,包含protected关键字.
2014年9月26日.protected关键字已登陆.它目前正在发布.如果您使用的是非常新版本的TypeScript,现在可以使用protected关键字...以下答案适用于旧版本的TypeScript.请享用.
class A {
protected x: string = 'a';
}
class B extends A {
method() {
return this.x;
}
}
Run Code Online (Sandbox Code Playgroud)
TypeScript只有private- 不受保护,这只在编译时检查时表示私有.
如果你想访问super.property它必须是公开的.
class A {
// Setting this to private will cause class B to have a compile error
public x: string = 'a';
}
class B extends A {
method() {
return super.x;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19933 次 |
| 最近记录: |