4 ms·
The Heart and Soul of Prototypal OO: Concatenative Inheritance
- vmorgulis 11y agoLooks like mixins: https://en.wikipedia.org/wiki/Mixin https://en.wikipedia.org/wiki/Mixin
- panic 11y agoThis "concatenative inheritance" seems like a symptom of JavaScript's limited support for prototypal OO. Objects in Self support multiple prototype slots: you can add to an object without copying more stuff into it.
- masklinn 11y ago> Objects in Self support multiple prototype slots Which it calls parent slots[0], the prototype being the "template object" originally copied/cloned to make the current object[1]. [0] http://handbook.selflanguage.org/4.5/langref.html#parent-slots http://handbook.selflanguage.org/4.5/langref.html#parent-slo... [1] http://handbook.selflanguage.org/current/glossary.html http://handbook.selflanguage.org/current/glossary.html
- cmrdporcupine 11y agoConcatenative inheritance predates JS. There were research languages in the 80s that had this model as well. This book (2003) has a good summary of the space: http://www.amazon.com/Prototype-Based-Programming-Concepts-Languages-Applications/dp/9814021253 http://www.amazon.com/Prototype-Based-Programming-Concepts-L... There's a diversity of approaches. Self uses prototype delegates. The language I learned on (LambdaMOO) has a single-delegate ("parent") model. There have been research languages that used pure concatenation. And even ones that had early binding and static types.
- Kiro 11y ago> Believe it or not, it is the most commonly used form of inheritance in JavaScript. Are extend, assign etc really more common than just working with prototypes? I've personally never used it but written a lot of OO code using prototype delegation.
- pluma 11y agoI'm not sure it makes sense to rank these two in terms of popularity as they're generally used for very different things. Delegation is heavily used in combination with constructors (both ES6 classes and traditional) and factories. Extension is typically used to apply default values, merge data objects or update multiple properties at once. The use of extension in a way that could reasonably be called a "form of inheritance" is mostly limited to mixins, which I would say aren't more popular than using prototypes (at least not obviously so).
- pluma 11y agoThat's a pretty grandiose term for a pretty straightforward pattern in JS. Other people just call it "mixins" but I guess there is some elaborate academic argument for why that's an entirely different concept even if the two are indistinguishable to the layperson.