3 ms·
"Who doesn’t like explicit inheritance, like in Java language, instead of writing magic code for prototypal inheritance?" There's nothing magical about prototy
by tejohnso 9y ago
"Who doesn’t like explicit inheritance, like in Java language, instead of writing magic code for prototypal inheritance?"
There's nothing magical about prototypal inheritance code, and I'd suggest the class keyword is more magical since it's "primarily syntactical sugar over JavaScript's existing prototype-based inheritance" [1]. Furthermore, encouraging classical inheritance constructs without mentioning the classic pitfalls is somewhat harmful [2].
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[2] https://medium.com/javascript-scene/javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e https://medium.com/javascript-scene/javascript-factory-funct...
- Raphmedia 9y agoI never understood the whole confusion about prototypal inheritance. It's not harder to grok than classical inheritance. "Which Java developer doesn’t miss classes when switching to a JS project?" ... That's the biggest problem here. Java != JavaScript. You shouldn't blindly carry concepts from one language to the other. Adding syntactic sugar with the only goal of pleasing developers coming from other language goes against my view of what features should be added to a language. That's code bloat.
- dahart 9y ago> I never understood the whole confusion about prototypal inheritance. It's not harder to grok than classical inheritance. I'd guess, mostly based on my fuzzy memory of my first exposure to prototypal inheritance, that this confusion stems almost completely from the fact that prototypal inheritance is simply different from classical inheritance. Having come from a C++ world, I didn't realize there was another kind of inheritance, until I met JavaScript.
- masklinn 9y ago> I never understood the whole confusion about prototypal inheritance. It's not harder to grok than classical inheritance. In theory no, but Javascript has such bad support for it that it's syntactically inconvenient and you have to understanding significantly more details of the implementation to manage it than just "you add the other class after the extends".
- shados 9y agoPretty simple really: lots of people learn Java or other languages with similar inheritance models in school or very early in their careers from books/peers. It takes a while, and it's used in a lot of places. JS style inheritance is a bit more unique (compared to other languages commonly used on the job). Even though its arguably simpler, it's not something nearly as many people know, especially relative to how many people know JS. Thus it becomes this big scary thing. A bit like Monads that take minutes to learn but are scary because no one knows them.
- pducks32 9y agoAgreed. When I go from Ruby to Haskell I don’t try and eat hem to add Classes. That wouldn’t make sense. Why should JavaScript be different.