This course has been updated! We now recommend you take the TypeScript Fundamentals, v3 course.
Transcript from the "Inheritance" Lesson
>> Mike North: So in terms of how inheritance works, if we have a class like this, we can create a subclass by using the extend keyword. And in addition to that, we get a super keyword that can be used to call methods on the parent class, or to call parent class's constructor.
[00:00:19] I say it's a keyword just because it can be used in two different ways. So here is our subclass of Employee, and you can see that Employee takes an id and a name. It makes sure, using this parent constructor here. It makes sure that when Employee's constructor says, Person constructor, do your thing.
[00:00:40] Make sure you store this name I'm giving you, as member data on this object, it just has to pass that name along. And we're treating super like a function here, and then we can do whatever we wanna do. Later on, we can use super a different way, and here, we are getting a parent prototype's method, we're saying super to JSON.
[00:01:02] So essentially, we're basically extending the result of what Person was doing for this function, and adding something to it. We'll worry about what those three dots mean later. But I just want you to see that in a constructor, typically, you invoke super as if it's a function. In other member functions, you use super as a reference to sort of the parent class version of, typically, one's own function, right?
[00:01:29] So often, you see this pattern where you're into JSON, you're implementing it there and you would call super. Which would be like, do what your parent class was gonna do, and then we can incorporate that into whatever the subclass is doing. So in this case, if we did something like this, we would end up with not only name being in the JSON, but the Employee's id as well.
>> Mike North: So earlier, I mentioned this concept of species, I'm not gonna give you an exercise on species. I do want you to kind of understand this as one of two examples we're gonna see over this course, of how symbols are used.