3 ms·
In other languages, classes are a special entity. In JS it's just another object, and you can copy methods from one object to another. Benefit is that you can c
by megous 8y ago
In other languages, classes are a special entity. In JS it's just another object, and you can copy methods from one object to another. Benefit is that you can create mixins, for example.
- NathanKP 8y agoYep, the concept of the "prototype" is very integral to JavaScript, and I think its often not understood fully. I actually like the mixin concept much more than multiple inheritance, as I find the mental model to be a bit clearer. For example the "diamond problem" is very clear with a mixin and easily resolved (latest mixin wins) vs more confusing in many languages (looking at you Go with "ambiguous selector" error.)
- megous 8y agoYes. I use it all the time. What's the best is that you can extend existsing prototypes and add your own functions even to native/host objects. And with a use of Symbols it's quite foolproof.