Live data from Hacker News

A summary of ECMAScript 6 features

github.com

21–30 of 54 posts

Re: A summary of ECMAScript 6 features

#21

What's the story behind `let` becoming the new `var`? Seems odd to me to change the short hand for "variable" to `let`.

`var` is still there, but it is scoped differently - `let` scopes to blocks, e.g. if (foo) { let baz = 'quux'; ... }

`let` in function scope is the same as `var`, in block scope it's narrow, it's basically the thing you want. `var` couldn't change, though, it would have broken existing code - hence `let`/

Re: A summary of ECMAScript 6 features

#24

ECMAScript 6 is a mess Now there's a completely new function syntax that doesn't use parens and has different scope rules var odds = evens.map(v => v + 1); Enhanced object literals: // Computed (dynamic) property names [ 'prop_' + (() => 42)() ]: 42 what?? So it uses parens if there are no params, but not otherwise? Template Strings: `In JavaScript this is not legal.` Seriously another String delimiter? `Hello ${name…

    let fibonacci = {
      [Symbol.iterator]() {
        let pre = 0, cur = 1;
        return {
          next() {
            [pre, cur] = [cur, pre + cur];
            return { done: false, value: cur }
          }
        }
      }
    }
    
    for (var n of fibonacci) {
      // truncate the sequence at 1000
      if (n > 1000)
        break;
      print(n);
    }
I love how the only comment is explaining what "if (n > 1000) break;" does

Re: A summary of ECMAScript 6 features

#25

A lot of these features look great, and some of them are even useful. I think it's a shame that async/await has to wait for ES7. It would really give some direction to the node community and give JS an edge for async programming. Generators just look like another awkward attempt to avoid callbacks by jumping through different hoops.

As much as it sucks that it probably won't be in v8 or iojs native for a bit.. you can use co/koa for now, or you can use 6to5 or another transpiler to get the async/await features now.

Re: A summary of ECMAScript 6 features

#26
Unfortunately Symbols are not that useful when it comes to private properties in classes. A better approach would be to use use weakmaps to have private properties.

The problem with symbols is the absence of symbol literal syntax(along with the fact that one can access symbols through reflection).

Re: A summary of ECMAScript 6 features

#27

Earlier quoted context omitted.

Generators in Python are a very useful feature (lazy sequences, like you said), so maybe I spoke to soon. However, I don't think people should be lauding this feature as some kind of solution to callback hell. I just feel like priority-wise, users would benefit most from modules (which made it), async/await, maybe class syntactic sugar, then everything else.

> I don't think people should be lauding this feature as some kind of solution to callback hell. Then async/await is no solution for it either.

I think:

    app.get('/thing', function (req, res) {
      try {
        await user = db.get({user: req.user});
        res.send({user:user});
      } catch {
        res.send(400);
      }
    });
beats the hell out of:

    app.get('/thing', function (req, res) {
      db.get({user: req.user}, function (err, user) {
        if (err) return res.send(400);
        res.send({user:user});
      });
    });
especially when you have conditionals or loops that can look like:

    if (user.name == 'abc') {
      resp = 5;
    } else {
      await resp = db.get_resp({user:user});
    }
    await db.save(something);
I suppose it doesn't get rid of callbacks, just makes them readable.

Re: A summary of ECMAScript 6 features

#28
Maybe its just me but the only things that I really like from this document are "Unicode", and "Tail Call", though some other things may be nice, the verbosity is killing me, how many new keywords, synatic constructs, and symbols are coming in with ECMA6? Though I have no say in the matter, for my 2 cents, I just wish they had used ECMA6 to remove things (mainly those listed here: http://johnkpaul.github.io/presentations/empirejs/javascript... and in Crockfords famous book http://archive.oreilly.com/pub/a/javascript/excerpts/javascr...) for instance.

Re: A summary of ECMAScript 6 features

#29

Earlier quoted context omitted.

Generators have long been used in the Python community for reasons other than callback avoidance (they are lazy sequences). Generators in ES6 (as well as several other features) seem to be inspired by Python. There's no reason we'll have to wait for ES7. Seeing as how good 6 to 5 transpilers already are, I'm sure you'll be able to use await relatively soon.

Generators in Python are a very useful feature (lazy sequences, like you said), so maybe I spoke to soon. However, I don't think people should be lauding this feature as some kind of solution to callback hell. I just feel like priority-wise, users would benefit most from modules (which made it), async/await, maybe class syntactic sugar, then everything else.

FWIW, most of the stuff I've read on using generators to wrangle async has stressed that that's not the aim of the protocol, it's just a useful side-effect. But I think you are right, which is a bit of a shame really, given how useful generators can be - most every detailed article quickly skips through pretend toy examples, then aaaand async

Re: A summary of ECMAScript 6 features

#30
post #19
post #14

It's really hard to find browser support information for each of those. And every browser vendor chooses to develop every feature in different pace and order.

http://kangax.github.io/compat-table/es6/

I know about that. But seemingly it only shows limited set of browser versions.

For me the most important thing is: what was the first version to support this feature. So I know I can actually use it -- comparing to my users' browser usage stats.

Post reply on HN