February 2019
Beginner
694 pages
18h 4m
English
As we discussed briefly in the opening chapter, TypeScript introduces the public and private access modifiers to mark class variables and functions as either public or private. Additionally, we can also use the protected access modifier, which we will discuss a little later.
A public class property can be accessed by any calling code. Consider the following code:
class ClassWithPublicProperty {
public id: number | undefined;
}
let publicAccess = new ClassWithPublicProperty();
publicAccess.id = 10;
Here, we have defined a class named ClassWithPublicProperty that has a single property named id. We then create an instance of this class, named publicAccess, and assign the value of 10 to the id property of this instance. Let's ...
Read now
Unlock full access