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.

Constructor pattern

Constructor pattern - JavaScript Tutorial

From the course: JavaScript: Patterns

Start my 1-month free trial

Constructor pattern

- [Instructor] Similar to the class prototype pattern, the constructor pattern is one step further from the class pattern, where we leverage a class created to create an extended class from it. Let me demonstrate. So we'll leverage our car class here, and as you can see we already have a constructor, but the actual pattern itself is something else. So the constructor allows us to create a new object from the class. But what if we would like to create an SUV class and extend this class from it? And that's what the constructor pattern is and why you would use it. So let's go ahead and do that. So the first thing I'm going to do is create a new class called SUV. And we're going to extend the car class. So basically we're leveraging the constructor we already have in this class, and then we'll extend it with other items. So let's go ahead and do that by creating the class and then the constructor will still have doors…

Contents