OOP with TypeScript: Read Only & Static Members

TypeScript
Transcript

English (Auto-generated)

the class And sorry, read only only Member. And the static member in the typescript. Opie So the read only. First of all, we're gonna talk about the read only member. So I'm gonna create a class um from from its name. What do you think it is? Actually? You know, we creator, we we've talked about the private classes. So sorry, the private members. So the reader read only members are what the private members cannot be accessed outside of the um the class you have to use together or the several function to use the private members. But the read only members can be can be redid but you just cannot access them. You cannot modify them. So or I think you can access them but you just cannot modify them. I'm gonna show you the example here. Okay, So this is a simple, you know, a simple member which is a string. Ok, that's understandable. And I'm going there and I'm simply creating let and I'm writing oh BJ one equals two new space person. Okay, that's simple. Now you go there and you right. Oh, BJ one full name and uh equals two. And you write something like, you know, Mark. Okay. And I'm not gonna do anything for now because we already know that. I mean we didn't get it in the console log, let's just get it console the log. And I'm calling Oh, BJ one dot full name simple now, TSC and then I need to write the notes, script dot Js And here I've got the Mark. So basically this is a simple name. I mean simple property. I just declared it inside the I declared it inside the I declared it here but defined it inside the class anyway. What if I simply call it private now? I cannot modify it here. I also cannot call it like I did right here. Okay, so let's just do one more thing um create a private property age and it is a string And now that is simple public. This can be accessed, this can be modified outside of the class simply but we just cannot access this one. We cannot modify this one outside. We just cannot simply call it without the getter and the setter function but read only. And here I am creating one more general um generally is not good but uh um collection sprain okay with the read only property we have to give some value where we are defining the class. Okay, so I'm assigning something like you know students? Students Okay, what I'm doing here is I'm simply I'm simply calling, I'm simply telling that this property, I mean this this is a person glass and this this is a collection of many students. I mean you know, so um now you if you just go there and you or just go there and you're like, oh BJ one dot collection equal to and you write something like no, it won't work because if I have the mouse over there cannot assign to a collection because it is a really only property understandable but you can access it. That collection. I mean you can simply right console the log and inside that you just simply can put this now you can access that. You can read the value of the property but you just cannot modify the difference between the private and the read only. I think it is pretty much simple and clarified no doubt um script dot Js you can see that the marks, Mark and the students because the collection is the collection name is the students. So we got it and we got the full name which is Mark. I mean it works but you just simply cannot modify it. Okay, there is one more thing which is is okay. And here what is the status thing? The person plus or um no be static property traveling. Okay, this should be the string. Okay, that is understandable. Now, what is this thing you actually can when it's stated, you just simply cannot use it within object. For example, if I write oh, BJ one dot I'm still only getting the collection and the full name but not this property. This unique property will be um will be you know loyal to the to its class. So to call this study property, you need to write person dot restated property for example, console the log and inside that simply cut that and paste it inside and save it. Now you can see that the person dot the aesthetic properties. So now you can call the aesthetic property which is inside the person. If I go there and I write PSC and I write notes, spaces, script. Or you can see that. Oh, it is, it is undefined. Yeah, it is undefined because there is no value. So, sorry. Um I mean that's okay, but just go there and put some property, some value, like, you know, the stated value. Save it. Now go there and clear this up and write PSC and right, A node script dot Js. And now you've got it marked students, they stated value. So, you know, it is, it is, it is actually, you know, directly can be called Wyatt. The class, but not from the object. It is not the part of the object. Even though everything of this class is a part of the it's it's, you know, inherited or you know, became the part of the object. The object can use all of these these properties, but not the stated one. This is the beauty. I think. I I think you've now got the read only and aesthetic members. So in the next video, we're absolutely gonna talk something else until then stay tuned
126 Views 0 Likes 0 Comments

Read-only & static members in TypeScript.

Comment
Leave a comment (supports markdown format)