Live data from Hacker News

ES6: The features I'm most excited about

justicen.com

61–70 of 144 posts

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

#61

When will browsers start to implement these features? I'm looking forward to being able to use modules in Chrome.

The other features? Already being done: https://kangax.github.io/compat-table/es6/

Modules? That may be a while, and isn't a big concern since until HTTP2 is in wide effect (which may be really soon anyways) it makes more sense to just package the files in to one file (which you can do right now) using Browersify, JSPM, Webpack, or what have you than having the client request a whole bunch of javascript files at once.

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

#62
post #52

Earlier quoted context omitted.

async function foo() { try { const valueOne = await promiseReturningFunction(); const valueTwo = await anotherAsyncFunction(valueOne); return valueTwo; } catch (err) { alert(err); } } foo(); //Returns a Promise. ---- In this example, I've sequenced the resolution of two promises (async functions return Promises when invoked) If either of these Promises reject or throw an error, or if any of the code within the try {}…

I see. Not sure what the best practice is for the losing scope in then chains issue with promises. I ended up creating something along the lines of a message object designed for each chain, which felt like a smell.

Feels like an un-compiler-assisted State monad.

IMO threading an object through is probably the best method, unfortunately. You could use an Immutable Record or something to help keep it under control.

I would personally just use async/await to more explicitly handle the sequencing/binding.

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

#63

I've just been playing with Promises and like them a lot. But one thing I find strange is that ".then()" creates a new promise, but with no way to reject it. ie. I can't write: return new Promise((resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. }).then((step1Val, resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. // But this doesn't actually work, b…

.then() does create a new promise. Return Promise.reject() in the fulfillment function to reject the new promise. somethingThatReturnsPromiseWithoutError() .then((res) => { return Promise.reject("some error"); }) .catch((err) => { console.log(err); // => some error }); Promise.resolve() and Promise.reject() return a promise resolved or rejected to the value passed in the first argument. Returning a promise in the ful…

It took me a while to understand this correct response because I couldn't understand the documentation for promises. For the benefit of any other person who was likewise confused...

then() returns a new promise resolved to the return value of the function. However, if that value is itself a promise, then it follows the promise chain and passes the eventual state to the next then()/catch() call.

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

#64

I was just talking to my friend who works at NetFlix on the frontend team about ES6, he is most excited about destructuring `let { name, age, gender } = user;`. I however advocate that the new class syntax is the best part of ES6. Take the following trivial OOP example, which I think reads so much easier a lot like PHP. "use strict"; class Vehicle { constructor(name) { this.kind = 'Vehicle'; this.name = name; } print…

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.

All code in modules is in the context of "use strict" by default so it won't be necessary to use this pragma explicitly.

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

#65
post #60

I think .bind(this) could be added as a (more common?) alternative example to var self = this; Personally I'm most excited about the module system. It's by far the most confusing thing for our students (and hard to google since you end up going down the rabbit hole of build systems etc.)

With the introduction of arrow function you won't need to use .bind(this) as arrow functions capture in their lexical scope the variables/keywords: this, arguments, super.

e.g.

setTimeout(function(){alert(this.a)}.bind(this));

becomes simply

setTimeout(() => alert(this.a));

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

#66

I was just talking to my friend who works at NetFlix on the frontend team about ES6, he is most excited about destructuring `let { name, age, gender } = user;`. I however advocate that the new class syntax is the best part of ES6. Take the following trivial OOP example, which I think reads so much easier a lot like PHP. "use strict"; class Vehicle { constructor(name) { this.kind = 'Vehicle'; this.name = name; } print…

I think it's fair to say that people who want to write object-oriented Javascript are very excited by class. Those of us who have found that the non-OO nature of Javascript is part of what makes it so productive are... much less excited.

[deleted]

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

#67
post #25

Earlier quoted context omitted.

Yup. It's as if coffeescript was created by one person (and a bunch of great PRs!), while ES6 came out of a committee.

That's exactly what I like about ES6 (the fact that it has come out of a committee and is now a standard).

What the hell ?

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

#68
post #36

Earlier quoted context omitted.

Or better, Promise.reject

Both are useful, but I'd hesitate to call it better. What makes you say it is better?

It makes explicit that the intention that a promise should be rejected, as opposed to a throw where one might reasonably expect an exception of some sort.

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

#69

Earlier quoted context omitted.

I think it's fair to say that people who want to write object-oriented Javascript are very excited by class. Those of us who have found that the non-OO nature of Javascript is part of what makes it so productive are... much less excited.

JavaScript is object oriented just like any other language. The difference is that it is prototype-based OO instead of class-based OO. I would say that JavaScript's OO is actually more powerful/flexible than other languages but it is less readable and more error prone if you're not careful - For example, the fact that objects can 'borrow' a method from other object an apply it to themselves is a common source of issu…

A lot of other languages makes you write a lot more code for some things that js can express very shortly. I usually find that the js version is more readable. The problem, I think, is that most programmers are used to class-based inheritance and not prototypical inheritance.

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

#70
post #2

My favourite feature is promises, while it doesn't add a new syntax and you can probably add a library for it, the fact it's standardised makes a world of difference. Now that it's standardised 1. It will become the common interface for deferred operations and library authors can make assumptions that it's there. 2. ES7 Async/Await will be able to leverage this common interface.

My problem with promises is that delivering it without async/await is just awkward. Because, yes, in the ES7 async/await world, you're going to want to use promises heavily because they'll work so great with that. But in the ES6 world, making your API promise-based makes it heavier-feeling and more awkward than simple, clean callbacks. (Which get an unnecessarily bad rap from people who don't work primarily in JS; th…

For the near term, you have to use something like babel anyway. Beyond that, generators and promises need to be implemented ahead of async/await as they are prerequisites for it.
Post reply on HN