Deep JavaScript Foundations, v3

Prototypal Class

Kyle Simpson

Kyle Simpson

You Don't Know JS
Deep JavaScript Foundations, v3

Check out a free preview of the full Deep JavaScript Foundations, v3 course

The "Prototypal Class" Lesson is part of the full, Deep JavaScript Foundations, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Kyle presents a code example of a class system written using prototype to highlight data relationships.


Transcript from the "Prototypal Class" Lesson

>> Kyle Simpson: The same class syntax. But this is like the underneath the sugar, this is what the code would look like. This is the old school way of doing a prototypal class, so called. You notice that we have a workshop function which is going to serve sort of the purpose of the constructor.

And then we start adding methods to the Workshop.prototype, and we cog new calls and stuff. So you see some of the underpinnings of classes, but this is the plumbing underneath what is happening in the class sugar. It's not that you would really write this code anymore because if you wanted to do classes at all you almost certainly be using the class syntax.

You wouldn't write this prototypal code anymore, but I think it's important for you to understand how this plumbing works. Where are the relationships? Where are all of those linkages? Since they're not copies and since copying is actually a bad mental model, we need a different mental model that helps us understand how class works, how it really works, so that we can understand when it breaks, why did it break?

Why did it do something different than what we expected?

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now