Live data from Hacker News

ES6: The features I'm most excited about

justicen.com

91–100 of 144 posts

Re: ES6: The features I'm most excited about

#91
post #86

I'm a bit worried about ES6 making the language harder to understand. For example, scoping: For backwards compatibility reasons, var has to stay function scoped. But now we also have let, which has different scoping rules. Also, Symbols: [Symbol.iterator]() - what? Why?! On the other hand, stuff like arrow functions, template strings, modules and tail optimization are awesome.

Can someone explain the reasoning behind having any kind of backwards compatibility? Who would pick a worse-but-compatible ES6 over a better incompatible version? For example, the scoping rules: why have two separate scoping rules for let and var? To put it another way, would ES6 have let and var with differing scoping rules if it was designed today? If not, then it's a flaw (any difference from what a clean redesign…

What about it is not simple and consistent? Two different syntaxes, and two different expectations and rules. Var is function scope, and let is block scope.

Re: ES6: The features I'm most excited about

#92
post #88

I agree with this list completely, but it doesn't mention one of the best reasons generators and promises are awesome: async/await-style asynchronous programming eliminates callback hell by letting you write asynchronous code as if it were synchronous, including using control structures like conditionals, loops, and try/catch. And you can do it in (most) browsers today using a transpiler like Babel and a library like…

The problem with Javascript generators, however, is that you're not allowed to call other functions from them, which yield. This very much limits the kind of async stuff you can do with them.

Not really (at least not the kind of stuff I mentioned), those functions can just return promises which the caller yields: http://codepen.io/anon/pen/WvzGLa

Granted async/await syntax will make this a bit nicer:

    async function funcA() {
      await sleep(1000);
      // ...

Re: ES6: The features I'm most excited about

#93

Earlier quoted context omitted.

Why can all this new syntax be added, but the "use strict" pragma is still specified by a string? It made sense to send messages to the interpreter in a backwards compatible way, but now it just seems odd.

Not entirely sure if browsers require "use strict;", but io.js (node) does.

In iojs/node, you can force v8 strict mode through the --use_strict flag, saving you from writing in every file.

Re: ES6: The features I'm most excited about

#94
post #90
post #76

I don't understand why everyone considers classes controversial. If you look at code in the wild, it already does what classes desugar to: everyone already writes constructor function and attaches properties to their prototypes. At least now with classes, users coming from other languages wont be as tempted to make their own completely incompatible object systems.

While my example isn't an issue in ES6, most of the controversial came from CoffeeScript. Using classes comes with classical inheritance expectations. In CoffeeScript, changing class variables would carry through all instances, and that is unexpected from a classical inheritance point of view. However, it made complete sense in the compiled JS.

Maybe I'm misunderstanding, but isn't that the same as static properties on classes in Java?

Re: ES6: The features I'm most excited about

#95
post #76

I don't understand why everyone considers classes controversial. If you look at code in the wild, it already does what classes desugar to: everyone already writes constructor function and attaches properties to their prototypes. At least now with classes, users coming from other languages wont be as tempted to make their own completely incompatible object systems.

It is more the "extends" than "class" that is controversial because it eschews other pattern like mixins.

Re: ES6: The features I'm most excited about

#96
post #91

Earlier quoted context omitted.

Can someone explain the reasoning behind having any kind of backwards compatibility? Who would pick a worse-but-compatible ES6 over a better incompatible version? For example, the scoping rules: why have two separate scoping rules for let and var? To put it another way, would ES6 have let and var with differing scoping rules if it was designed today? If not, then it's a flaw (any difference from what a clean redesign…

What about it is not simple and consistent? Two different syntaxes, and two different expectations and rules. Var is function scope, and let is block scope.

I feel like in a new design you would pick one or the other, as a second scoping rule would not carry its own weight in terms of what problems it solves vs the complexity of implementing runtimes or learning the language. In that case I'm almost certain you would go for block only as it is the default in nearly all curly braced languages.

Re: ES6: The features I'm most excited about

#97
post #88

Earlier quoted context omitted.

The problem with Javascript generators, however, is that you're not allowed to call other functions from them, which yield. This very much limits the kind of async stuff you can do with them.

Not really (at least not the kind of stuff I mentioned), those functions can just return promises which the caller yields: http://codepen.io/anon/pen/WvzGLa Granted async/await syntax will make this a bit nicer: async function funcA() { await sleep(1000); // ...

But then the called functions have to be written async style.

Re: ES6: The features I'm most excited about

#98
post #76

I don't understand why everyone considers classes controversial. If you look at code in the wild, it already does what classes desugar to: everyone already writes constructor function and attaches properties to their prototypes. At least now with classes, users coming from other languages wont be as tempted to make their own completely incompatible object systems.

In es6 it's finally possible to properly subclass internal types, it properly separates Class properties and prototypes, and it allows users to extend arbitrary classes.

Re: ES6: The features I'm most excited about

#99
What's the point of promises being part of ES6?

I understand them and use them quite a bit. I just don't understand why they're in the language spec. They don't add anything new to the language (vs say generators or symbols).

Is it purely for performance?

Re: ES6: The features I'm most excited about

#100
I was a little confused by the constructor for Player in the class example. Wouldn't the following be more appropriate:

  constructor(x = 0, y = 0) {
    this.x = x;
    this.y = y;
  }
(i.e. this way if "new Archer('Legolas', 5, 6);" the x and y values will not be ignored.)
Post reply on HN