From the course: Learning TypeScript
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Encapsulating logic and data with access modifiers - TypeScript Tutorial
From the course: Learning TypeScript
Encapsulating logic and data with access modifiers
- [Instructor] Now that we've added type-metadata to a class, let's revisit the idea of Private Variables. When I first walked through this class, I mentioned that adding an underscore to variable names, is a very popular convention to identify variables that should not be accessed outside of the class. I also mentioned, that in JavaScript, the underscores don't actually do anything, they're just a suggestion. Well, TypeScript does a little better than that. Like most object oriented languages, TypeScript provides us with the ability to hide, or encapsulate some or all of our class members, by using something called Access Modifiers. These modifiers are, private, which means that the member is only visible inside of the class. Protected, which means that it's visible inside of the class, as well as visible to any other classes that derive or extend from that class it's defined in. And finally, public,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.