Live data from Hacker News

ES6: The features I'm most excited about

justicen.com

31–40 of 144 posts

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

#31
post #13
post #5

Wow. I can't believe template strings ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ) aren't in this list. I'm incredibly excited to start having those at my disposal.

Hm, at first glance I am as well, especially with tagged template strings. Those look particularly simple but powerful. Generally though, is it reasonable for features such as these to be included at the language level? I primarily use ES5 JavaScript so I'm used to pulling in a decent amount of modules (in this case handlebars, underscore, etc.) for things like templating. But I will be relieved to have a language-st…

Yes, for at least two reasons:

Unsafe string-munging is too easy and seductive. Doing things the safe/secure way needs to be at least as easy.

And it makes for a growable language, the way Lisp macros do. E.g. https://github.com/erights/quasiParserGenerator This can reduce the demand for feature bloat in future language standards.

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

#32
post #19

Earlier quoted context omitted.

There is a way to reject it in the .then() callback. You just throw.

So in the first function you call reject, but in the second function you throw? I don't love the asymmetry. Also how do you return a value from the second callback? Just return? If throw and return work that way for then() functions, why not the same for the initial function?

Because the initial one is where you'd interface (potentially) with non-promise code. E.g. in order to wrap a node-style function, you can't throw or return. But in general you shouldn't need to use `new Promise()`, that should in most cases be reserved to more general, low-level code (e.g. a promisify implementation).

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

#33
post #17

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…

async/await solves error handling and hanging onto values quite nicely. IMO you should use Babel and take advantage.

link to example please

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

#34
post #24

Earlier quoted context omitted.

[deleted]

> .then() does not create a new Promise It returns a promise, right? > var foo = Promise.resolve([1,2,3]).then(function() { return 5 }) > foo

I'd think it would return the original promise, for chaining.

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

#35
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 Blurebird, Q, co, or task.js.

The rest of the things are nice, but promises/generators (and eventually async/await) are game-changers.

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

#36
post #19

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…

There is a way to reject it in the .then() callback. You just throw.

Or better, Promise.reject

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

#37

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.

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 issues for beginners.

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

#38

Earlier quoted context omitted.

new Promise(function(resolve, reject){ /* code */ }) it's a little much

Ideally, if you're writing business logic, you shouldn't be creating promises but consuming/combining/chaining them from libraries.

What would make you say that? Why wouldn't you use promises in your business logic?

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

#40

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…

Of course, with proper tail calls, you can get generators and any kind of control structure almost for free :)
Post reply on HN