DEV Community

Discussion on: What are, Mixins?

Collapse
 
jwkicklighter profile image
Jordan Kicklighter

Hey there, I'm a little confused about this article. Are Mixins a real thing? Are they an idea you're presenting? Are they something upcoming in the JS spec?

Collapse
 
elugens profile image
Stacey Wilson

A mixin is a class containing methods that can be used by other classes without a need to inherit from it. In other words, a mixin provides methods that implement a certain behavior, but we do not use it alone, we use it to add the behavior to other classes. It just shows that class based inheritance is not as flexible prototypal inheritance.

Collapse
 
bhagatparwinder profile image
Parwinder 👨🏻‍💻

Hey Jared,

Great question and thanks for reading. Mixins are definitely real. There are times when you’d want to inherit from multiple classes or objects.

That being said there is no official way of implementing Mixins with JS. The lack of true inheritance or composition does lead to myriad of implementation techniques.

Would you ever need it? Maybe not.

Adding object oriented principles to JavaScript might not be fruitful in my opinion but I do bring them up for awareness.

Collapse
 
perpetual_education profile image
perpetual . education

What do you think about 'stamp' ? medium.com/javascript-scene/introd...

Thread Thread
 
bhagatparwinder profile image
Parwinder 👨🏻‍💻

Thanks a ton! As much time as I spend with JavaScript, I am surprised I had not heard of this. That means I have no opinion on it.. yet.

This gives me something new to learn over the next week or two. I appreciate that you brought it up.