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.
Mixins pattern - JavaScript Tutorial
From the course: JavaScript: Patterns
Mixins pattern
- [Instructor] Mixins are a great way to mix functions and instances of classes after they have been created. In other words you could use mixins to add interesting functions to the car class we created earlier. So let me demonstrate. So I'm back into the index.js file right here from the base, so if you don't have it open you can grab it from the exercise files in the resources, and let's go ahead and add some code to this file here. So right now we have the car class, we have the car factory, we have the SUV class and the SUV factory. So what we're going to do is create a mixin that will have a console log with a rev engine, a message, so let's go ahead and do that. So the first thing I'm going to do is add a mixin right after my SUV factory, so line 39. So what I'm going to do is create a mixin by doing let car mixin equals and then this is going to be a function, and this function will basically be a console log so…
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.
Contents
-
-
-
-
-
(Locked)
What are structural patterns?55s
-
(Locked)
Module pattern5m 54s
-
(Locked)
Mixins pattern4m 32s
-
(Locked)
Facade pattern1m 43s
-
(Locked)
Flyweight pattern1m 18s
-
(Locked)
Decorator pattern2m 16s
-
Model-View-Controller (MVC) pattern1m 21s
-
Model-View-Presenter (MVP) pattern1m 17s
-
(Locked)
Model-View-ViewModel (MVVM) pattern1m 25s
-
(Locked)
-
-