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

Kyle introduces the next core foundation to cover in the course, Object-Orienting: this, Prototypes, class {}, and "Inheritfance" vs. "Behavior Delegation."

Get Unlimited Access Now

Transcript from the "Object-Oriented Introduction" Lesson

[00:00:00]
>> Kyle Simpson: Our final unit of discussion for the workshop is object orienting. And I wanna make sure that we've fully get the right scope if you will of what we're gonna talk about. So, let's look at the things that we wanna address. We need to first address the this keyword.

[00:00:18] You're gonna get a chance to practice that on your exercise in just a moment. But why don't we get a chance to practice this keyword? But really, what we're getting out is we need to understand the prototypes system cuz that's how people implement object oriented code in JavaScript.

[00:00:35] Typically, they use the prototypes system. And we're gonna look at the pro's and con's of that approach. We're gonna also look at the new class key rid that was added in the ES6, we're gonna look at why the class key word helps with some things but we're also gonna look at some problems that the class keyword creates.

[00:00:54] Overall, the outcome of that discussion is I don't use the class keyword and I don't recommend you do either. I know that there's a ton of people that are like following all over themselves, excited about the class keyword. I think it was a bad idea to add to the language.

[00:01:11] I think it actually created more confusion rather than clearing it up. And it only appears to be useful because it fixes a few syntactic issues while creating deeper conceptual problems. So my takeaway in that is that I don't use the class keyword. As a matter of fact, I've never even taught the class keyword all up in to this point.

[00:01:32] This is the first time I'm even teaching it because I don't want to make it sound like I'm endorsing that I think you should use it. But I also think it does you a disservice if I don't explain what it's doing cuz you're likely to see this in lots of code that you work with.

[00:01:45] So, I at least want you to understand it but I'm not endorsing that you should do class or any code. As a matter of fact, as we get through this part of our discussion, I'm gonna be pointing out that I don't think class oriented design belongs in JavaScript at all.

[00:01:59] As a design pattern, it just doesn't belong. But I'm gonna replace it with something that I think is a lot more natural. And that design pattern is the behavior delegation design pattern. So rather than implementing inheritance and using syntax or other kinds of tricks to do that, I think we should be going for behavior delegation.

[00:02:16] The best way for me to describe the comparison here, is to take the term OO, which we know means object oriented. Unfortunately, object oriented really isn't object oriented, it's really class oriented. When people say OO, they usually think of Java and C++. That's the traditional classical class implementation.

[00:02:38] That's all about classes. Now, notably Alan Kay, the inventor of the [LAUGH] concept said, when I invented object oriented, I did not have at all in mind what they did with C++. But it doesn't really matter what Alan Kay intended because most people that come to JavaScript come to it through the path of Java or C++, and that colors their opinion that classes are done a certain way.

[00:03:03] So we'll address what classes mean from the perspective of most people's experience. And point out that OO is really class oriented. So I need to show you, what is delegation? I need a catchy term for that, and I can't use OO, so I used OLOO. This is a comparison between OO which stands for object oriented but really means class oriented.

[00:03:24] And OLOO which means, objects linked to other objects. Actually, OLOO is the real true object oriented. It really is oriented only around objects and not around classes. But unfortunately, OO has already been taken, so OLOO. So that's where we're going with our discussion the rest of the workshop.