|
|
|
|
|
by treehau5
3432 days ago
|
|
There are many other languages that do not have multiple inheritance, or do not handle it the way you typically see in C++ or Java type languages, go being one of them, ruby another. Composition is more favored, and arguably a far better pattern regardless. I disagree with your assessment that it prevents sound encapsulation, and regardless, a better argument made against it is the fact that it is a dynamic language. In any way, there are patterns to achieve classical OO-style encapsulation, but that is not the main point of object oriented programming in any case. |
|
Encapsulation isn't the "classic version" of OO. It's literally the main reason OO was created. Javascript fails to encapsulate because it doesn't support true private data members. There's patterns to achieve some sort of data safety (see http://speakingjs.com/es5/ch17.html#private_data_for_objects) but they all have disadvantages because it isn't built into the language, it's another hack.
Composition can be easily achieved using interfaces in most languages, another thing javascript doesn't support.
Excusing these faults to being dynamic language is like saying the model T is a nice car because "it was good for its time". Many languages before JS (including perl even) supported a more sound and convenient type system.
JS was badly designed in many ways and we are still paying the price for it today. ES6 and transpiling have made it finally worthwhile to try to develop anything significant using it which has led to the recent explosion of javascript development. I pray that EMCA continue to remedy what can be fixed in future and that Typescript catches on since it mows over much of the insanity.