Mixins in JS

ref – https://blog.bitsrc.io/understanding-mixins-in-javascript-de5d3e02b466

Mixin is a way properties are added to objects without using inheritance — Darren Jones
Mixins are a form of object composition, where component features get mixed into a composite object so that properties of each mixin become properties of the composite object. — Eric Elliot

Let’s create a destination object to contain all the data.

Then we create a whole bunch of other objects with properties.

Finally, we’ll write our custom assign to “mixin” these objects with properties into our destination object like so:

The result of mydetails would be:


{surname: “qi ji”, firstname: “ricky”, occupation: “Software Developer”}
surname: “qi ji”
firstname: “ricky”
occupation: “Software Developer”
__proto__: Object

It mixed in all the properties of the other objects.