Check out a free preview of the full Deep JavaScript Foundations course:
The "Clearing Up Inheritance" Lesson is part of the full, Deep JavaScript Foundations course featured in this preview video. Here's what you'd learn in this lesson:

In classical inheritance, properties and methods of a class are copied to object instantiated from that class. Subclasses inherit the properties and methods of a parent class and copy them to their instantiated objects. Kyle contrasts that with JavaScript's "prototypal inheritance" or "behavior delegation."

Get Unlimited Access Now

Transcript from the "Clearing Up Inheritance" Lesson

>> Kyle Simpson: I've talked badly enough I think at this point about inheritance, and class-oriented design and why I don't think it's good. I wanna to move towards something that's better, I wanna clear up some misconceptions about it. So, in a traditional classical inheritance system, we have apparent class. And we copy down to the instances and we copy to the child and copy to instances.

[00:00:27] So the arrows go from left to right and top to bottom, these are copy operations. In JavaScript, regardless of what syntax you use, what we actually have is that an object, and then another object, and another one, and another one, and another one, and another one, and all of those.

[00:00:46] The linkage goes from right to left and bottom to top. This is not a slight nuanced difference, this is a completely, my God, entirely different system. And its a really powerful system that we are not fully taking advantage of. There's a different designed pattern here that we have been completely missing out on, there's another design pattern.

[00:01:11] So what I really wanna do is were gonna finish out by talking to you about the different designed pattern that simplifies what we do, and gives us more power. And that design pattern is called Behavior Delegation. So, that will be our last topic of discussion, Behavior Delegation. What I mean by delegation is back to this example, when I say a1.speak, a1 doesn't have a speak method.

[00:01:38] But we delegate from a1 to another object so that that method call can happen. It just happens to be a weirdly name Foo prototype here, but delegation is an object-oriented concept. Is not a class concept is an object concept.