February 2019
Beginner
694 pages
18h 4m
English
When using inheritance, it is sometimes logical to mark certain functions and properties as accessible only within the class itself, or accessible to any class that is derived from it. Using the private keyword, however, will not work in this instance, as a private class member is hidden even from derived classes. TypeScript introduces the protected keyword for these situations. Consider the following two classes:
class ClassUsingProtected {
protected id : number | undefined;
public getId() {
return this.id;
}
}
class DerivedFromProtected
extends ClassUsingProtected {
constructor() {
super();
this.id = 0;
}
}
We start with a class named ClassUsingProtected that has an id property that is marked as protected, and a ...
Read now
Unlock full access