OOP with TypeScript: Super Keyword

TypeScript
Transcript

English (Auto-generated)

in typescript. So absolutely, we're gonna follow the typescript while talking about the, you know, Opie. So the thing is first of all we're gonna make a class. We've already have done this so you know how to make a class for sure. But let's just make it quick. Okay. The person and then the person, you know full name and you need to know while I'm talking, you need to know why I'm doing this. Okay. I'm making a property for this class and then I'm making the second property which is the age and it has to be the number. And then we're creating the next thing after the age which is um general. It has to be this training. Okay. And then after that, after the dinner um there is one more thing I'm matting which is nationality. I mean it can be Ukrainian, it can be, you know, um um you know, american, it can be mexican, it can be Canadian or any anyone, anybody. I mean, you know, so the nationality should be the string again and then okay, these are four for properties in this class. Now we're going further and what we are going to do by now is hmm, okay. Um, here is a class, Sorry not the class but the object P one Khan's P one equals 2 and the P one is, you know, new person. Okay, I've created an object which is which has all these properties and you know, I can put the data for example, I can no, I can write things. P1. name equals to um Jack Cobb The Jacob and P one age equals 2 29 P one dot general equals two um meal, sorry the meal is not a boolean, it has to be this ring, we're not talking about the the typical male bravado and he can be right every time anyway. Sorry, Okay then the nationality, let's make the Jacob as Canadian Canadian, Okay, the Canadian nationality and what more I can do is um you know the Jacob the nationality. Okay now I'm gonna go back there and I'm gonna create um a method which is like you know any action, you know, Jacob has all these properties. Now what Jacob does Jacob walks, okay, so this is a method, I mean sorry, not to Jacob but the person walks, it can be Jacob, it can be anybody but for now it walks, that is simple. And uh I'm going inside and I'm making something, I can make anything um person walks okay, that's understandable. Now I'm simply going to go there and if I right sorry if I write, you know um counseled a log and mm hmm I don't think I need the control dialog, I need p one dot walks and I need to, what I need to do is I need to go there and I need to make the PSC so now the gps script is now converted into the Js, so this is the Js script and now the nodes pays the script dot Js and then okay, person walks? We got it. We don't need to make this inside the console walk because, you know, the console log is already happening here. So all we need is to call this function, which, which we did, which is a method here. Okay. The person walks, but uh, I'm going further and I'm making and I actually, I'm not going further, I'm going here, I'm making another class, which is, you know, um, this is, there's, this is something else. It is a chef, okay, a chef or let's let's speak to students Actually students. Okay, students. And they go inside. Why I'm creating this class right here because, you know, this is a kind of collective data. So when you're creating new problems, new new variables, the variables should be at the top of the programming. This is a, you know, a general rule. However, it is not very necessary, but you just don't create or declare a variable wherever you want to use it. Instead, you just declare all the variables above. So similarly, I'm using this in the same structure. The same pattern. I'm I'm declaring the class and the person above. So here, um uh classes student. And what I'm doing here is uh um, I'm just going inside and I'm making things like, you know, the grade grade. Okay, string. Now what I'm doing, I'm simply instead of making a new object, I'm extending Okay, I am extending this, sorry, not exporting, but extends person. Okay, so now this should be the student, What is happening here? Or let me delete that because I don't want to confuse you. I'm making a new object. Const s one equals student. New student. Okay. And this means that I just have nothing happening. Okay, go down. No problem. Just hover the mouse over there over there. Okay. Okay. As one that, you know, you can see that we are getting everything from the, you know, from the person and we're also getting the data from the students itself, the grade, you can see that. So the full name, it can be anything like I'm again writing jakob or instead of Jacob like this. Right? Um joseph. Okay, that's awesome. As one dot age. The age of joseph can be, you know 22 And that's one. and it can be um meal Nationality Equals two Spanish. OK. S one got grade. The great is um um b grade, be positive, be plus or b minus but B plus. Okay, this is the grade of, you know that this is student, but S one dot works. I'm simply, you know, using the S1 over um Yeah, as one dot walks now if I just go there and I clear this and I write PSC and then they know this script dot Js and the person walks, we are getting the person walks, but when it is about the student, it should be the student walks. Okay? Now, just simply creating another walks here and you know what's gonna happen, I'm gonna tell you exactly, so um I'm returning something here or I should be returning something here too, I'm returning a string and uh why not? Mr Turner valley, Okay. Instead of the console log, I am using the return and going this way, Okay, I'm going to tell you the reason why I'm doing that anyway, I'm going here and it has to be, it is the string to now, I'm going inside and what it is telling him declared in another one. Okay, It has to have a valley. A return return. Okay? And what is returning here, student walks now, what is happening here? Actually, Now this won't work because we need to use this inside a console log. I did it on purpose because I want to use the other properties to so um what is happening here is what is new happening here is, you know, we already have a function which is which name is walks and if you're extending everything from the person into this new class and Okay. Yeah, uh and I think the the grade, the grade is only in the student, but everything we're, you know, inheriting from the person that is totally understandable, but the box is, you know, uh is uh we are overriding the box, so this one is the original box. This one is the overriding uh the box. So when you're creating the object using the student class, so it's gonna have everything but it's going to override this walks into this club this walk. So we're gonna have this walks for now. So now um we just cannot go with this way, so console the log and okay save it, go to the browser and I'm writing PSC note, sorry, note the script dot Js a student walks. What is the meaning of student walks when we have already, you know, two walks because you know this one is overriding double one because um the object of the class we assigned to this object is the student weren't understandable. Now let's move further. We want to use the above method in this class while having the the new one. So how to do this, I'm going inside and I'm writing super okay. And uh here um walks, no student, not the student works, but what's in that walks? Wait a minute. Okay, that's good. Now, so what we're doing here um Sorry, I was using a bad practice, let's just make it simple. Super dot walks. So when I write super okay, what I'm doing here is exactly by using the super keyword, I can, you know, I this one the walks is overriding the above data, but what I'm doing here is is simply um you know overwriting the above method but also bringing the data by calling the super the super means this class, the super class because this is a subclass because this class is taking everything from the person and absolutely we can have thousands of classes which would be using the data from the person, you know, the student, the teacher, the barber, they cook the chef or everything, everybody, so we are getting the data from the person. So this is a super class. So you just need to talk super dot walks or you know maybe at some place you are updating the general, the nationality, you know, you can also override these properties here. So to call the actual property from the, you know, the the above the super class. You just need to write super super dot and you can, you know, call everything from the super um super class. Now I need to go to the browser and I'm sorry I'm not going to go to the browser but the terminal, so first I'm gonna clear and then PSC and then okay, once it's done, no um script dot Js and now a student walks because we are only talking about the student walks okay, this one is okay. Yeah, console dot log. This has to be the console log Yeah, what I'm doing here because this function is returning some text. This function is returning the text person walks but the what it is returning is not being, you know called into the any console or something. So first of all, whatever we are getting here has to be, you know, returned or we can use this in, in at this point of return. Anyway, let's just try this PSC no script dot Js and then person walks, student walks the student walks is actually the return of this walks method. The person walks is coming from the super dot walks means the super class. So in that way we are even overwriting, but we are also getting the data from the above, from the super class, everything as it is, and we can use this in the, in the subclass and you know, we then we can, you know, do whatever we want, this is the data, you can use this data into the console log, you can save this data into the properties, you can do a lot of thousands of things can be done because we just got the data using the super q words. So I think this is actually a super keyword, so super powerful, I think we had enough talk about it and then now we are able to move to the next topic until then stay tuned
176 Views 0 Likes 0 Comments

What exactly is the 'super' keyword?

Comment
Leave a comment (supports markdown format)