News for hackers. Stuff that matters.
Re:Arrow Functions Coming to Chrome 45 by apalmer on Monday June 22, 2015 @02:04PM (#9760089)
No Offense, but arrow functions and the 'let' keyword in particular just seem like really bad ideas for javascript.
Re:Arrow Functions Coming to Chrome 45 by rcfox on Monday June 22, 2015 @03:34PM (#9760669)
Arrow functions and `let` are what is generally considered to be the "correct" way of doing things. They behave more closely to how other languages behave, and should reduce overall confusion in the long term.

The arrow operator is indeed syntactic sugar for binding `this` to the function. It's not really necessary, but it makes it much easier to do what you expect to do 99% of the time.

Yes, it sucks that there are now two slightly different ways of doing things, but it's better than breaking all of the existing code currently in use. Hopefully, linters and analysis tools will mark `var` and non-arrow functions as deprecated soon after the major engines support ES6.

Re:Arrow Functions Coming to Chrome 45 by paublyrne on Monday June 22, 2015 @02:17PM (#9760183)
No offence taken, but what about let do you think is wrong for JavaScript? It will help make common scope errors less common, and is clean to read.
Re:Arrow Functions Coming to Chrome 45 by apalmer on Monday June 22, 2015 @03:00PM (#9760448)
basically i feel like it greatly complicates the scoping rules in order to make javascript scoping similar to other languages scoping rules. If there was no 'var' I would be fine with 'let' and in theory perhaps 'let' is better than 'var', however if i had a choice between having both or having just one, i would rather just have either, even if the either is 'var'.
Re:Arrow Functions Coming to Chrome 45 by spb on Monday June 22, 2015 @08:29PM (#9762012)
If you think of `var` as a syntactic sugar for a `let` declaration that gets hoisted to the top of its containing function, `let` actually simplifies scoping.
Re:Arrow Functions Coming to Chrome 45 by aikah on Monday June 22, 2015 @02:09PM (#9760129)
why? i'd say if es6 had only 2 features one should be at least => .
Re:Arrow Functions Coming to Chrome 45 by apalmer on Monday June 22, 2015 @03:06PM (#9760492)
Arrow functions are worse, as far as I can tell the only benefit is to save a few characters of text. To get this win, now I have to always be conscious of how a function was created which syntax was used and as a result how 'this' was bound.

basically it is a 'fix' to a unusual but completely working and simple to reason about programming feature by adding a more correct but very inconsistent with the rest of the language that makes the whole thing harder to reason about.

does it serve any other benefit? I might be missing something as many people love this feature.

Re:Arrow Functions Coming to Chrome 45 by nacs on Monday June 22, 2015 @03:28PM (#9760636)
> does it serve any other benefit

Yes, as stated in the linked article:

> arrow functions don't define this or arguments in their bodies, instead capturing these values from the environment

Also:

https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functio...

Re:Arrow Functions Coming to Chrome 45 by steego on Monday June 22, 2015 @03:27PM (#9760628)
When I'm working with C#, I often write code like so:

    products
      .Where(p => p.Price >= range.low && p.Price <= range.high)
      .GroupBy(p => p.Category)
      .Select(g => new { Category = g.Key.Name, Count = g.Count() })
It's not just about saving a few characters. It's about about making certain types of libraries readable by reducing the amount of noise.