Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

The private access modifier

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content