4 ms·
Why would you ever recommend against using actual ES6 classes? Not only is it the new standard, he’s coming from Java... TBH, the only reason that seems to mak
by chrismeller 9y ago
Why would you ever recommend against using actual ES6 classes? Not only is it the new standard, he’s coming from Java...
TBH, the only reason that seems to make sense is some kind of weird “I knew JavaScript before it had classes!” kind of sentiment that wouldn’t actually teach him anything of value.
- thinkxl 9y agoPrototypal inheritance plays a huge role in understanding the language because JavaScript uses it for everything. It might be a good idea to learn about this before using ES6 classes; remember that ES6 classes are syntactic sugar on top of prototypal inheritance anyway. They wouldn't learn legacy patterns, but the actual pattern that JavaScript uses.
- chrismeller 9y agoI grant you that it plays (or at least played) a huge part, but as things move towards ES6 classes (which are very similar to every other language with classes), I would still argue that you’re insisting upon learning prototype inheritance for no real reason.
- thinkxl 9y agoYou are missing the point; if you use JavaScript, you use prototypal inheritance whether you like it or not, e.g.: function getUser() {} That is creating an instance of the `Function` constructor object[1][2]. In a Classical (as classes) language, you would see that like this: // `Function` being a class function getUser extends Function {} but because JavaScript is purely prototypal, this works differently. You say that there's no reason to learn prototypal inheritance, well, the only and valid reason is that to write at least decent JavaScript you have to understand how it works behind the scenes. * [1] - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... * [2] - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Edit: add links
- chatmasta 9y agoI use ES6 classes every day, and I would recommend it. However, for someone coming from a language like Python, it's easy to get confused over inheritance issues where JS does not behave like Python (or Java for that matter). It doesn't need to be extreme. I just recommended writing one or two "classes" using the old style, in the beginning, because that's a great way to solidify understanding of how the inheritance actually works. Whereas when you're using ES6 classes, you're using hidden abstractions that can make debugging very confusing if you don't know what the "class" keyword is doing.
- chrismeller 9y agoI came from a C# background, not Java, but didn’t find anything supremely confusing about class inheritance in JS. Differences to be sure, but nothing that was groundbreaking. Debugging I can see as being a reasonable argument - as you step through code you should understand what “proto” means. That’s the most compelling reason I’ve seen thus far...
- MoTTs_ 9y agoOn the contrary, classes and inheritance in both Python and JavaScript behave basically the same. In Python, classes are objects (a building, not a blueprint), and inheritance is done by delegation. https://i.imgur.com/p9Kw815.png https://i.imgur.com/p9Kw815.png If you've used Python classes and inheritance all this time and never felt confused, then people can also use JavaScript's classes and inheritance and never feel confused.
- tytytytytytytyt 9y ago> The "class" keyword is just syntactical sugar on prototypical inheritance so it's a good idea to learn the raw form before the sugared form. Idk how he could be more clear about why.