Transcript from the "Prototypes Introduction" Lesson
[00:00:29] What was a constructor call?
>> Speaker 2: A function called with the new keyword.
>> Kyle Simpson: A function with the new keyword in front of it. That's essentially where objects are gonna come from, okay?
>> Kyle Simpson: Now, it's often said that that constructor call is gonna make that object based upon a constructor's own prototype, but this phrase based on is problematic.
[00:01:21] The blueprint metaphor being, there's a blueprint for a building, but that building doesn't exist until the builder takes that blueprint and physically makes the building out of it, right? In a sense, that process of taking a blueprint and making a building out of it. I would argue the essence of that is a copy operation.
[00:01:44] Specifically, what I mean by that is the characteristics listed in the blueprint are copied to the physical building. It is not that there's some kind of live link relationship between the two. That relationship exists, only in the instant in which we copy the characteristic from blue print to physical building.
[00:02:03] And then it ceases to have that relationship. If I go to the blueprint, and I erase a wall It doesn't take the wall out of the real building does it? They're not linked. If I go to the building and I knock out a window, it doesn't erase the window from the blueprint does it?
[00:02:22] Because they're not live linked. There was a copy. There is a separation in their relationship. That relationship was simply a copy relationship. Furthermore when we talk about inheritance in class-oriented coding, the genetic metaphor is usually used. Genetics like when you biologically create an offspring. So I have a son and when he was created, biologically he got a copy of my DNA.
[00:02:47] It was clearly a copy of my DNA not my own DNA but a copy of it. Now, we are two separate individuals. If he breaks his leg, my leg does not get broken. If I lose my hair, hopefully he doesn't lose his hair.
>> Kyle Simpson: Because our relationship biologically was a copy relationship.
[00:03:09] Every follow that? The same is true in class oriented coding. When we instantiate something from a class we conceptually think about that as being a one time event. We don't think about there as being a link between the instance and where it came from. If a utility If a language allowed you to instantiate an object, and then modify the class definition after you had instantiated the object, would you expect for that object instance to be able to have the new behavior?
>> Kyle Simpson: If I broke my leg, would you expect for my son's leg to get broken? There's a term for this, it would be retroactive inheritance. There's an actual term for it. But most people don't choose to imply retroactive inheritance as their design pattern for their code. So if you had a system that allowed retroactive inheritance and you used it, there's a more likely chance that people reading that code might get a bit confused.
[00:04:41] That we made the object as a copy of the constructor's prototype.