You can protect yourself from overriding data you shouldn't. In this video, learn about readonly and how it protects your data model's most important pieces.
- [Instructor] Read only is the last major access modifier … that stops us from overwriting a value. … It does pretty much exactly what you think it would do. … Gives us the readability only on a property. … Now let's take a look at our message class. … And like most models that come from a server for instance, … you'd expect there to be some sort of ID or primary key, … and read only is a very practical and realistic example … of how that might work. … So if we have read only on an ID, … we'll say this is a string, … this is going to give us the ability … to not overwrite this value once it's instantiated. … So we can make this private … if for some reason we only needed to use it … in our actual class itself. … We could make it public … if we want to read it from outside the class. … And we could even make it protected … as we would other places. … We'll go ahead and just leave it as public … so that we can show it for demo purposes. … You'll also notice that in our constructor, … if all we were passing for instance was an ID, …
Skill Level Intermediate
TypeScript: Upgrades and Featureswith Emmanuel Henri1h 15m Advanced
TypeScript for Node.js Developerswith Emmanuel Henri1h 2m Intermediate
1. Classes in TypeScript
2. Inheritance in TypeScript
3. Access Modifiers in TypeScript
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.