Mixins - Basic JavaScript Fast (28) | Object.assign
Вставка
- Опубліковано 5 вер 2024
- In JavaScript, if we want to add functionality of a class, we can get it from another object without establishing inheritance. This pattern is called a mixin.
Playlist of my JavaScript course
• [20 hours] JavaScript ...
Playlist of my HTML5 and CSS3 tutorials
• [12 hours] HTML and CS...
Playlist of my algorithm walkthrough
• Algorithms and data st...
Playlist of my Java course
• [14 hours] Java tutori...
Playlist of my Java examples
• Java projects for begi...
#javascripttutorial #javascriptfullcourse #begincodingfast #javascript #mixin #object.assign
Thank you! This was great. Straight to the point, good definition and easy to understand.
I was trying to figure out how to use mixins with classes in JS. I tried using other classes as mixins but didn't work the way I wanted to. They either didn't work properly with Object.assign or got overwritten with Object.setPrototypOf. Just making the mixins as objects and using Object.assign works nicely!
So glad that my video helped you understand mixins. Thank you for watching my videos too.
Aren't Mixin objects? Even the assign method takes target and source(s), all as objects. That means Mixin is an object that uses methods from other object(s).
In this example, the Object.assign method takes two objects to vary the original class definition. Therefore, it is more reasonable to say that a mixin is a class.