December 2017
Beginner
372 pages
10h 32m
English
The protected keyword behaves similarly to private, with the exception that protected variables can be accessed in the derived classes. The following is one such example:
class base{ protected id: number;}class child extends base{ name: string; details():string{ return `${name} has id: ${this.id}` }}
In the preceding code, we extend the child class with the base class, and have access to the id property inside the child class. If we create an object of the child class, we will still not have access to the id property outside.
Read now
Unlock full access