Peter Seliger
May 25, 2024

... quoting ... "...we use the Object.assign method and bind the mixin to the object’s prototype" ... nope. Object.assign does what is says, it assigns all of an object's enumerable properties/methods to another object, here, as for the OP's example code to User.prototype. Binding targets functions exclusively and involves context or/and arguments.

... more quoting ... "Mixins allow objects to borrow functionality from them ...". In JavaScript every real mixin approach is based on the direct assignment of the additionally needed methods/behavior. The term borrowing is true only for the special case of applying a mixin directly to a prototype object. The borrowing (actually it's delegation) then is due to the prototype based delegation mechanism which takes place when an object does not directly own a method/property.

No responses yet