3 ms·
ECMAScript 6 is a shame, there's a lot of stuff added which is unnecessary. "let" is unnecessary. JS now has two kinds of variable scoping! "var"'s hoisting is
by TazeTSchnitzel 11y ago
ECMAScript 6 is a shame, there's a lot of stuff added which is unnecessary.
"let" is unnecessary. JS now has two kinds of variable scoping! "var"'s hoisting is annoying, sure, but we don't need two kinds of variable scope. If you want to scope something to a block, you can just use an IIFE.
"class" is unnecessary at best. JavaScript has a bunch of ways of constructing objects to choose from, and that's not a problem. Why lock users into one paradigm, and obscure what's actually happening underneath? This will just confuse people when they have to deal with code that doesn't use "class" syntax or the OOP model it presents.
Object property shorthand is confusing. Why the hell is {bar} equivalent to {bar: bar}? Isn't that a set literal (Python, math)? Why isn't there the colon, if it's an object? What the hell? Try explaining that to newcomers.
Computed property names looks weird and is misleading. You'd logically expect {[1+1]:2} to be an object with an Array (coërced to string?) key, because [] is an Array literal. But instead it means "compute this expression". In which case, why isn't it ()? That's what you'd intuitively expect. I've tried to use () before and was surprised it didn't work, even.
Method properties, e.g. { foo(a,b) { ... } }, are unnecessary given => functions.
All that being said, I think ES6 has some quite positive additions. Maps, sets, tail-call elimination, =>, modules and symbols are all very important and useful features JavaScript really needed.
- benaston 11y agoI think the jury is still out on `class`. I can say that `class` is somewhat "dishonest" both the sense that it makes the language more complicated, under a guise of simplification; and in the sense that it lures developers from classical languages into thinking that JavaScript has classes in the same manner, when `class` in JS is just sugar.
- phpnode 11y agoI see this line of thinking a lot and I think it's a mistake. Are classes in other languages consistent with each other? Clearly not, so why is this distinction made here? ES6 classes ARE classes, it's not just sugar, that is what they are.
- TazeTSchnitzel 11y agoNo, it's just syntactic sugar. They're not a basic construct of the language. JavaScript has objects and it has prototypes on objects. ES6 classes are sugar over this. Classes in other languages, however, are the basic construct.
- phpnode 11y agoWhy is this distinction important when it comes to actually using the language?
- TazeTSchnitzel 11y agoBecause when you run into OOP that doesn't use the sugar, you'll have trouble if you'd only learned "class", rather than what it's syntactic sugar for.
- Arnavion 11y ago>If you want to scope something to a block, you can just use an IIFE. Now try doing that in a loop that you want to break out of. Edit: To save you the trouble - https://github.com/babel/babel/issues/644 https://github.com/babel/babel/issues/644 >"class" is unnecessary at best. ... Why lock users into one paradigm? It canonicalizes one of the popular ways of doing classes (the other being the same but without `new`). >Why the hell is {bar} equivalent to {bar: bar}? Isn't that a set literal (Python, math)? { ... } in JS has never meant set literals. It does however mean objects (dictionary literals) which is also how Python uses it. >You'd logically expect {[1+1]:2} to be an object with an Array (coërced to string?) key, because [] is an Array literal. [] has also always been used to index objects and arrays, so using it when generating the object with keys and values follows as an extension of that. >Method properties, e.g. { foo(a,b) { ... } }, are unnecessary given => functions. Arrow functions capture lexical this, which method properties do not. Compare `({ x: 5, foo() { return this.x; } }).foo()` with `({ x: 5, foo: () => this.x }).foo()` Arrow functions also do not have an arguments object.
- TazeTSchnitzel 11y ago> Now try doing that in a loop that you want to break out of. Fair point, although this can be worked around. Though it begs the question of why you need block scoping anyway. If you have a function large enough to need it, you should probably break it down into smaller functions, and compose them. > It canonicalizes one of the popular ways of doing classes But there are other popular ways, and this way new users will have the underlying details hidden from them, meaning they'll encounter problems later. It's also potentially misleading. > { ... } in JS has never meant set literals. Yes, but it's never been { a, b } - there's always been a colon. Python also uses {} for dictionaries, but with colons. Having { a } magically use the variable's name as a key name, and also use the variable's value, is unintuitive. { a, b } in another language would be an array (C, C++) or a set literal (Python, mathematics). Nobody would expect it to do what it does here in ES6. > [] has also always been used to index objects and arrays, so using it when generating the object with keys and values follows as an extension of that. I suppose that makes some sense, but we don't use [] for string keys in literals. > Arrow functions capture lexical this, which method properties do not. Oh, right, good point.