April 2018
Beginner
536 pages
13h 21m
English
If we use the private modifier, the method or property can only be accessed by the object that owns them.
The following example redeclares, once more, the classes that we declared in the preceding example, but uses the private access modifier instead of the public modifier. The example also adds a couple of extra methods to the classes to demonstrate the implications of using a private access modifier:
class Person { public name: string; public surname: string; private _email: string; public constructor( name: string, surname: string, email: string ) { this._email = email; this.name = name; this.surname = surname; } public greet() { console.log("Hi!"); } public getEmail() { return this._email; } } class Teacher ...