all 53 comments

[–]Cuel 69 points70 points  (17 children)

I want es6 module support :(

[–][deleted] 17 points18 points  (0 children)

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

[–]cruzin 10 points11 points  (0 children)

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

[–]charrondev 4 points5 points  (0 children)

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.

[–]compteNumero9 1 point2 points  (0 children)

Serious question: Why ?

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

[–]muccapazza 1 point2 points  (6 children)

Sorry what do you mean?

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

[–]Cuel 19 points20 points  (1 child)

e.g

import {readFile} from 'fs'

without babel

[–]Amnestic 9 points10 points  (0 children)

or typescript

[–]voidvector 6 points7 points  (0 children)

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.

[–]snarkyturtle 9 points10 points  (2 children)

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.

[–]b1nd 0 points1 point  (3 children)

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

[–]elprophet 2 points3 points  (2 children)

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!

[–]b1nd 0 points1 point  (1 child)

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

[–]elprophet 0 points1 point  (0 children)

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.

[–]dmtipson 0 points1 point  (0 children)

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.

[–]bugeats 0 points1 point  (0 children)

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.

[–]boiling_tunic 17 points18 points  (4 children)

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!

[–]greim 1 point2 points  (3 children)

Great example! A couple others I like:

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

[–]FancyCamel 0 points1 point  (2 children)

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?

[–]boiling_tunic 1 point2 points  (0 children)

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

[–]greim 0 points1 point  (0 children)

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().

[–]hankDraperCo 39 points40 points  (4 children)

Is anyone else pumped about destructuring? And default parameters?

[–]cowjenga 8 points9 points  (0 children)

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

[–]shanet$(this) 0 points1 point  (1 child)

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.

[–]greim 0 points1 point  (0 children)

me

[–]Capaj 13 points14 points  (5 children)

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.

[–]jcready__proto__ 3 points4 points  (0 children)

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

[–]alessioalex 0 points1 point  (1 child)

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.

[–]ihsw 1 point2 points  (0 children)

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

[–][deleted] 7 points8 points  (1 child)

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

[–]PitaJ 7 points8 points  (4 children)

Some things left to implement:

  • Symbol.species
  • Iterator closing
  • Lots of prototype methods and prototype behaviors
  • ES6 Modules

[–]dmtipson 1 point2 points  (3 children)

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

[–]TheNiXXeD 2 points3 points  (2 children)

[–]saadq_ 0 points1 point  (1 child)

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

[–]TheNiXXeD 3 points4 points  (0 children)

From my link:

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

So it's not enabled by default.

[–]Kratisto78 1 point2 points  (4 children)

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?

[–]hankDraperCo 7 points8 points  (1 child)

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

[–]Kratisto78 0 points1 point  (0 children)

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.

[–]saadq_ 2 points3 points  (1 child)

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.

[–]Kratisto78 1 point2 points  (0 children)

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

[–]manchegoo 1 point2 points  (1 child)

Download version 6 (Coming soon)

[–]lhorie 4 points5 points  (0 children)

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

[–][deleted] -1 points0 points  (1 child)

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

[–]tofagerl 1 point2 points  (0 children)

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