1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// @declaration: true
// @target: es5
// Class with protected members
class C1 {
protected x: number;
protected f() {
return this.x;
}
protected set accessor(a: number) { }
protected get accessor() { return 0; }
protected static sx: number;
protected static sf() {
return this.sx;
}
protected static set staticSetter(a: number) { }
protected static get staticGetter() { return 0; }
}
// Derived class overriding protected members
class C2 extends C1 {
protected f() {
return super.f() + this.x;
}
protected static sf() {
return super.sf() + this.sx;
}
}
// Derived class making protected members public
class C3 extends C2 {
x: number;
static sx: number;
f() {
return super.f();
}
static sf() {
return super.sf();
}
static get staticGetter() { return 1; }
}
// Protected properties in constructors
class C4 {
constructor(protected a: number, protected b) { }
}
|