课程: JavaScript: Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Class design pattern

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…

内容