3 ms·
ES2015 classes are not easier to learn for newbies, they're easier to learn for Rubyists and other people coming from OO languages. There's nothing hard about
by erikpukinskis 9y ago
ES2015 classes are not easier to learn for newbies, they're easier to learn for Rubyists and other people coming from OO languages.
There's nothing hard about this:
function Person(name) {
this.name = name
}
Person.prototype.greet = function() {
return "Hi, "+this.name
}
var me = new Person("Erik")
console.log(me.greet())
The syntax hurts your brain if you're used to looking at something else, but the control flow is actually very simple and totally transparent, unlike ES6, which does magical things that can't be understood by thinking about where the thread is moving.
- jhall1468 9y agoThere's zero magic. It is literally syntactic sugar and nothing else. Calling that magic is dishonest.
- erikpukinskis 9y agoOk, I can agree and I'll tighten up my use of "magic", reserve it for Railsy stuff where there's a lot of cpu cycles behind the scenes. It's an extra layer of indirection that you can't see in the debugger though. Not sure what to call that. I think calling me dishonest is a little strange. How is poor word choice dishonest?
- ubertaco 9y agoWhich is easier, explaining to your hypothetical total beginner what "Person.prototype" is and going down the rabbit hole of prototype-inheritance, and explaining how Javascript functions (unlike just about every other language's functions) can have attributes on them and can act like fake constructors and what "this" means in your example (and then later what it means in a different case, since it means so many different things)...or simply saying "yeah, we can define a new category, or 'class', of things called Person by saying 'class Person { ....'"?
- erikpukinskis 9y agoYou only think "class" is self explanatory because you already learned what it means.
- ubertaco 9y agoYes, but plenty of other non-programmers also learned what it means, when they first heard the English word. So it's not a huge conceptual leap. Whereas "prototype" has completely different English dictionary meaning, and thus requires in-depth redefinition.