Transcript from the "Prototypal Inheritance (A)" Lesson
[00:00:30] So let's step through an example of how the language was intended to be used. So we're gonna create a Gizmo. A gizmo is a simple object that has an ID and has a toString method. A toString method will produce the produce the word gizmo with the ID. Everybody see the gizmo.
[00:01:23] And we can wire up and that's the new instance that we're making, we can wire up all the constructor properties. So every constructor property points to the function that is the constructor. Okay, so we have server loop going on there and then we add the invisible prototype properties which are the things that they all inherit from.
[00:01:48] So our new gizmo inherits here from gizmo.prototype, which itself inherits from object a prototype. Okay, so if I try to that from the new gizmo, an ID, we find it right there. If we try to fetch from it a toString method, it doesn't have one there. So it tries to go there.
[00:02:37] Now, this gets really weird. So I'm gonna make a hoozit. Okay, and a hoozit is just like a gizmo, except it will inherit or it inherits all the gizmo stuff, but it also has a test method. Otherwise, it's just the same and the test compares the id for equality.
[00:02:56] So we'll take that. And now, look at it in terms of these structures. So filling in the prototype linkage, the inheritance chain. Okay, so if we want to go to a hoozit ID, we'll get it from the hoozit instance. If we want its test method, we'll inherit it here from hoozit.prototype.
[00:03:50] This stuff's laying out there. And now, this is totally weird. We replaced hooozit.prototypes with an instance of another object that doesn't look anything like extends. That's just holly weird. It also creates some other problems. For example, if I ask my new instance over hoozit, who is your destructor?
[00:04:11] Cuz maybe that's important to you. Well, that doesn't have a constructor. That doesn't have a constructor. We go up here and it says, it's a gizmo. It doesn't even know it's a hoozit. Now it's possible to repair that, but that's more work on your part. The system is not looking out for you here.
[00:05:03] And then when I want to inherit from hoozit, I just say, okay, you can extend to gizmo and here is your constructor function. So now it's at least neater, everything is contained. Is it better? I can testify that it's better, but it's at least neater. So this is it.
[00:05:39] And so everybody tries to put something on top of it to make it neater. I'm not sure this is the right way to think about it, but it's available.