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

Mixins pattern - JavaScript Tutorial

From the course: JavaScript: Patterns

Start my 1-month free trial

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…

Contents