r/javascript • • Apr 26 '16

Node.js v6.0 released - supports 93% of ES6 features

https://nodejs.org/en/blog/announcements/v6-release/
379 Upvotes

53 comments sorted by

68

u/Cuel Apr 26 '16

I want es6 module support :(

18

u/[deleted] Apr 26 '16

last thing keeping me compiling my big server project with babel. All those saved seconds would sure help.

10

u/cruzin Apr 26 '16

I got all excited until I saw they didn't support ES6 modules still.

4

u/charrondev Apr 26 '16

They were actually discussing the implementation of this on NodeUp. It was one of the more recent podcasts, but there has been a lot of discussion on how implementation will happen and things like interoperability. I'd give it a listen, it sheds some light on the challenges faced.

2

u/compteNumero9 Apr 27 '16

Serious question: Why ?

For compatibility/consistency with (babelified) browser code or do you see a notable advantage in es6 modules over require ?

2

u/muccapazza Apr 26 '16 edited Apr 26 '16

Sorry what do you mean?

EDIT: http://exploringjs.com/es6/ch_modules.html oh ok... but what is the difference with require?

19

u/Cuel Apr 26 '16

e.g

import {readFile} from 'fs'

without babel

9

u/Amnestic Apr 27 '16 edited May 05 '26

Databrokers? nope. Social networks? Also nope. This post was deleted using Redact.

many live price ink angle sink rob include meeting wine

6

u/voidvector Apr 26 '16

CommonJS exports a single JS object. ES6 exports a set of names, one of which could be default.

Also ES6 import/export bindings are done during compile time, which allow it to handle circular dependencies in a graceful/meaningful way (as in developer can do something about). CommonJS require/export are done during runtime, in the case of a circular reference, the behavior would change depending on which module get required first.

9

u/snarkyturtle Apr 26 '16

require and module.exports are commonjs, which isn't es6.

Here's a good article on the usage: https://ponyfoo.com/articles/es6-modules-in-depth

One of the advantages offhand is better static analysis which means for stuff like tree-shaking.

1

u/b1nd Apr 26 '16

Same! I thought it was in EMCA2015 right, but can't find it in the list here.

3

u/elprophet Apr 27 '16

The syntax and behavior for how symbols are handled between modules is well defined (http://www.ecma-international.org/ecma-262/6.0/#sec-modules), but the mechanism for loading files was left (deliberately) unspecified - http://www.ecma-international.org/ecma-262/6.0/#sec-hostresolveimportedmodule

HostResolveImportedModule is an implementation defined abstract operation

So all the rules of how modules behave are there, but it doesn't actually tell you how to load them!

1

u/b1nd Apr 27 '16

Thanks for the information, any news when node will support?

1

u/elprophet Apr 27 '16

I haven't been following the implementors specifically. My understanding is TC39 (the spec writing committee) is intending to leave that as-is, deliberately allowing platforms to choose the loading mechanism that works best for them. Originally there were rumors they were planning on specing that in the 2016/2017 updates.

1

u/dmtipson Apr 27 '16

Lot more likely that we'll see this in Node sooner than in browsers: not happening any there time soon. They built the spec, then nixed the loader implementation. Node at least doesn't have the same worries as browsers in coming up with a spec/implementation.

1

u/bugeats Apr 27 '16

I'm glad es6 module support is lower priority. I think it's overrated and offers very little advantage over the clean and simple CommonJS syntax.

It looks like a pain in the ass to implement too. So many different ways to do the same thing.

18

u/boiling_tunic Apr 27 '16 edited Apr 27 '16

Mmm delicious destructuring. An overview for those who are unfamiliar:

Old:

var result = getSeveralValuesInAnArray();
var a = result[0];
var b = result[1];

New:

var [a, b] = getSeveralValuesInAnArray();

For example:

Setup:

function min_max (arr) {
  let min = Infinity;                   // Let keyword. ES6 feature (not new in Node 6.0.0)
  let max = -Infinity;
  for (let x of arr) {                  // For...of loop. ES6 feature (not new in Node 6.0.0)
    if (x < min) { min = x; }
    if (x > max) { max = x; }
  } 
  return [min, max];
}

Old style usage:

var results = min_max([1,2,3,4,5]);
var min = results[0];
var max = results[1];
console.log('Min: ' + min + '\nMax: ' + max);

New style usage:

let [min, max] = min_max([1,2,3,4,5]);    // Array destructuring. New feature!
console.log(`Min: ${min} \nMax: ${max}`); // String templating. ES6 feature (not new in Node 6.0.0)

Aside: You can't run the new style code example alongside the old style code example as let will complain about redeclaring min and max

Edit: If anyone has any questions/feedback about any of the code in my post please let me know!

2

u/greim Apr 27 '16

Great example! A couple others I like:

var [ name, value ] = 'foo=bar'.split('=');
var [ protocol ] = 'http://example.com/foo.html'.match(/^.*?:/);

1

u/FancyCamel Apr 27 '16 edited Apr 27 '16

As someone that hasn't tried ES6 at all(but is curious), for your line:

var [ name, value ] = 'foo=bar'.split('=');

What would happen if the string being split was 'foo=bar=something'?

My understanding is that, currently, it would assign variables so that name=foo and value=bar, correct? So what would happen in the situation above with 'something' ? Is this only a method that you can use when you know for sure that the number of values returned will match the number of variables you're creating?

2

u/boiling_tunic Apr 27 '16 edited Apr 27 '16

Any remaining parts are discarded

Edit: Installed Node 6.0.0 to make sure I wasn't lying to you!

https://i.imgur.com/TiqF5QZ.png

1

u/greim Apr 27 '16

Yup, it's a contrived bit of example code that can definitely break on corner cases. It's nothing to do with ES6 actually, but rather the particular use of split().

38

u/hankDraperCo Apr 26 '16

Is anyone else pumped about destructuring? And default parameters?

9

u/cowjenga Apr 26 '16

Yes! Those two features alone (especially when combined) will make the first few lines of functions so much simpler/cleaner.

1

u/shanet $(this) Apr 27 '16

Far more than I should be. It's going to eliminate a lot of boilerplate. I'm curious what practices will emerge around parameter destructuring, I haven't seen much beyond simple examples so far.

13

u/Capaj Apr 26 '16

For me the single biggest feature are Proxies. I have even went ahead and implemented a small in memory DB experiment on top of them already. Very powerful stuff.

4

u/jcready __proto__ Apr 26 '16

That and the Reflect API are going to make for some awesome abstractions.

1

u/alessioalex Apr 27 '16

Be wary of performance though. Since it's just been newly released, it most like will be slow for a while until they optimize it.

Edit: I'm excited about Proxies too though.

2

u/ihsw Apr 27 '16

That's the most significant complaint about ES6 code -- it is currently much slower than ES5.

0

u/[deleted] Apr 27 '16

[deleted]

1

u/Capaj Apr 27 '16

Yeah, it was. But I tried to reimplement a chunk of mobxdb with ES6 proxies and I liked how it worked out and decided to ditch mobx in favour of https://github.com/capaj/proxevable

Hence the rename.

8

u/[deleted] Apr 26 '16

Performance improvements are key in this latest release with one of the most significant improvements coming from module loading, which is currently four times faster than Node.js version 4 (Node.js v4). This will help developers dramatically decrease the startup time of large applications for the best productivity in development cycles and more seamless experience with end users. In addition, Node.js v6 comes equipped with v8 JavaScript engine 5.0, which has improved ECMAScript 2015 (ES6) support. Ninety-three percent of ES6 features are also now supported in the Node.js v6 release, up from 56 percent for Node.js v5 and 50 percent for Node.js v4. Key features from ES6 include: default and rest parameters, destructuring, class and super keywords.

What does that mean when they say modules? Does that just mean the require() function or NPM or something else?

Edit

Nevermind: https://nodejs.org/dist/latest-v5.x/docs/api/modules.html

8

u/PitaJ Apr 27 '16

Some things left to implement:

  • Symbol.species

  • Iterator closing

  • Lots of prototype methods and prototype behaviors

  • ES6 Modules

2

u/dmtipson Apr 27 '16

Tail Call Optimization? Or is that in there already and I missed it?

3

u/TheNiXXeD Apr 27 '16

1

u/saadq_ Apr 27 '16

I don't believe it did, according to this at least.

4

u/TheNiXXeD Apr 27 '16

From my link:

Tail calling can be enabled by --harmony-tailcalls flag.

So it's not enabled by default.

2

u/Kratisto78 Apr 26 '16

Correct me if I'm wrong, but Koa required a flag until this was released. I've been planning to start my first node.js project, and I've been bouncing between Koa and Hapi. Does this push Koa a little ahead?

7

u/hankDraperCo Apr 26 '16

Koa said they aren't going stable with v2 until async/await wasn't behind a flag: https://github.com/koajs/koa/issues/533

async/await is still not a standard so that will still be awhile

1

u/Kratisto78 Apr 26 '16

Ahh that makes more sense. I figured I was wrong. Starting a new project with people that are all new to Node.js. Might just try Hapi to play it safe then. Thank you.

4

u/saadq_ Apr 26 '16

I believe Koa required a --harmony flag until Node v4.0.0. I think Koa is really going to gain in popularity once Node supports async/await which is what Koa v2 uses instead of generators.

2

u/Kratisto78 Apr 26 '16

Makes sense. Hopefully, I can transition to that when it finally is supported.

2

u/manchegoo Apr 26 '16

Download version 6 (Coming soon)

6

u/lhorie Apr 26 '16

The release build was taking a while, it's up for download now.

0

u/[deleted] Apr 27 '16

What are the breaking changes? I cannot find them on the changelog. Or are they ditching semver to celebrate?

2

u/tofagerl Apr 27 '16

Major releases CAN have breaking changes. They don't have to. That would be ridiculous.

-29

u/bart2019 Apr 26 '16

The version numbering scheme and especially the high speed by which the version number increases, is getting increasingly ridiculous.

What's this, a new major version for a few bug fixes, a speedup and some experimental features?

22

u/TheIncredibleWalrus Apr 26 '16

Node.js's versioning follows semver semantics.

Google it and study it (should take you about 3 to 5 minutes). You will stop being confused and you will also learn how 90% of all npm projects are being versioned.

6

u/sorahn on the cutting edge of cocking about Apr 26 '16

Considering its 4 months into the year AFTER the standard was finalized, I wouldn't call them "experimental".

2

u/ewan93 Apr 26 '16

I presume you haven't been burned by a package introducing breaking changes on a minor or patch version rather than major? Once you have, you appreciate semver more

1

u/tswaters Apr 27 '16

In a system such as this there may be many breaking changes -- if they released them immediately and followed semver, we'd be at version 1000 by now.

They batch them up with the tag 'semver-major' and every 6 months a new major version is released.

Each even numbered major version is LTS - you can realistically stay on LTS versions for a few years. Take a look at the LTS schedule for more information.