From the course: JavaScript: Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Class design pattern - JavaScript Tutorial
From the course: JavaScript: Patterns
Class design pattern
- [Instructor] In this chapter, we'll start covering all the patterns that are useful to create new items in your code, and we'll start with the prototype in class pattern. So in my course, JavaScript classes, we've explored this pattern with many examples, but in short, the prototype class pattern allows us to define a blueprint for a specific type of item, and then reuse it by creating a new object from that class. So let me demonstrate with some code. So let's go ahead and remove all that code. So if you want to keep it, save it into a different file. I'm going to go back to index.js and then create a class. So we'll create a car. So let's go ahead and create a class called car. And then in that class we'll use a constructor to define the blueprint of that class. So let's go in, create the constructor, and that car takes doors, an engine and it takes a color. So whenever we create a new car from that class we'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.