April 2018
Beginner
536 pages
13h 21m
English
If we use the protected modifier, the method or property can only be accessed by the object that owns them or instances of the derived classes.
The following example declares, once more, the classes that we declared in the preceding examples, but uses the protected access modifier instead of the public modifier:
class Person { public name: string; public surname: string; protected _email: string; public constructor( name: string, surname: string, email: string ) { this._email = email; this.name = name; this.surname = surname; } public greet() { console.log("Hi!"); } } class Teacher extends Person { public teach() { console.log("Welcome to class!"); } public shareEmail() { console.log(`My email is ${this._email}`); ...