Is a prototype inheritance for example defined as a composition or inheritance?
What are you guys thinking?
It is not about what I’m thinking but what the language core provides …
in the classfull-Style (c++) or in the traditional Design Patterns (GofPatterns) it is really clear, what is the difference between composition and inheritance and how it is implemented and when to use what (advantages/disadvantages).
But how do you distingish between Composition or the "normal" Inheritance in JS? or it is used as the same term?
… and of course one shouldn't bend concepts to much. Thus for JavaScript too, composition and inheritance count as much as for any other PL that supports these paradigms. JavaScript features Delegation, which already enables two variants of Code-reuse. Firstly, Inheritance, which in JavaScript is covered by a delegation automatism that is bound to the [prototype]
property of constructor functions. Secondly, Object Composition, which is based on explicitly delegating a function via one of it's call methods ([call]
or [apply]
).
Summing it up:
- Prototypal Delegation (Automatism) == Inheritance
- Explicit Delegation of Function Objects == Role based composition concepts like Mixins and Traits / Talents
- stepwise copying properties from one objects to another == another way of achieving kind of mixin composition
I already did provide examples in two other responses that are …
this
in an inherited method being the actual object instead of the method owner. So it all seems a bit muddled together. I guess I don't have a clear answer. – Mozambique