Ecmascript 6 Features Available in Node.Js 0.12

ECMAScript 6 features available in Node.js 0.12

Features without --harmony flag:

  • "for-of" loop
  • Map, Set, WeakMap, WeakSet (already specified in question)
  • Symbol (already specified in question)
  • Promise (already specified in question)
  • Array methods:

    • .keys()
    • .values()
    • .entries()
    • [Symbol.iterator]
  • Object:

    • .observe() (initially was planned for ES7, but was removed from the spec entirely on November 2, 2015)
    • .is()
    • .setPrototypeOf()
    • .getOwnPropertySymbols()
    • .getNotifier() (not es6, example here)
    • .apply() and .call() (not es6, same purpose as Funciton.prototype.call and Function.prototype.apply)
  • Number properties and methods (already specified in question)

    • .isInteger()
    • .isSafeInteger()
    • .isNaN()
    • .isFinite()
    • EPSILON
    • MIN_SAFE_INTEGER
    • MAX_SAFE_INTEGER
  • Math methods (a lot of them) (already specified in question)
  • constants

I thinks that's all that we have without --harmony flag.

Features with --harmony flag:

  • generators
  • arrow functions (without need of --harmony_arrow_functions flag in contrast to io.js)
  • let variables - only in strict mode
  • Binary and octal literals
  • String methods:

    • .contains() (was replaced by includes() in actual ES6 specification)
    • .startsWith()
    • .endsWith()
    • .codePointAt()
    • .repeat()
    • .normalize()
    • String.fromCodePoint
  • Proxy (behind the --harmony-proxies flag)

I think that's all. Maybe if I forgot something - I'll add it later to the list.

What version of Javascript is supported in node.js

This matrix (V8 follows the WebKit column fairly closely) seems to pretty well answer the question "what features can I use?" but I can't find a canonical answer to "what version of javascript is supported?" As far as I can tell, the best answer is this: ECMA-262 3rd edition is supported, but many features of the 5th edition are also supported.

There's a good explanation of why V8 follows the WebKit and JavaScriptCore functionality on this thread.

Ecmascript 6 support on Node.js

With regards to your second question, yes, there is es6-module-loader.
For a long list of transpilers, shims, and other tools for using full ES6 features now, see addyosmani's ECMAScript 6 Tools page.

As for native ES6 support in node.js, V8 officially implements "ECMAScript" but AFAIK the V8 project doesn't release a spec of their implementation.
However there are some sources of useful information out there.
Here's a brief overview of ES6 in node.js v0.11.6.

You may want to determine the version of V8 that your version of node.js uses.
See the node.js blog for recent changelog info.
It can also be useful to find the version of V8 used in a given Chromium release.
The Chrome release notes can be found here.
Keep in mind that different flags can be set for the same version of V8.
Chromium and node.js both have ways to set flags in V8 related to ES6 support.

Here are two tables that list ES(6) feature support across implementations:

  • http://pointedears.de/scripts/test/es-matrix/
  • http://kangax.github.io/compat-table/es6/

This MDN page lists a set of reference articles for ES6 language features.
At the bottom of each one you can see the status of Chrome support for that feature (and using V8 versions determine the support in node.js).

Finally, the V8 issue tracker
provides a list of issues related to ES6 features, many of which have been implemented and their issues closed.

string.includes('a') function not defined in Node.js 0.12?

String.prototype.includes is available in Node as String.prototype.contains. Check this out: http://kangax.github.io/compat-table/es6/. Look at the flag 26.
I think, originally the name proposed in the standard was contains but then it has been changed due to compatibility issues.

V8 Pull Request : https://codereview.chromium.org/742963002

You can check what options are supported by your node version by using node --v8-options | grep harm. Make sure you're using an update version of node.

This is the output for node version 0.12.2

Giuseppes-Air:development giuseppe$ node --v8-options | grep harm
--harmony_scoping (enable harmony block scoping)
--harmony_modules (enable harmony modules (implies block scoping))
--harmony_proxies (enable harmony proxies)
--harmony_generators (enable harmony generators)
--harmony_numeric_literals (enable harmony numeric literals (0o77, 0b11))
--harmony_strings (enable harmony string)
--harmony_arrays (enable harmony arrays)
--harmony_arrow_functions (enable harmony arrow functions)
--harmony (enable all harmony features (except proxies))

As you can see from the output, arrow strings ( => ), strings and array are enabled when the harmony option is used.

If you want to fully enjoy ES6, I would suggest to use babel and babel-node. String.prototype.includes is correctly supported.

es6 support in a current node version

You can find the list of features enabled with and without --harmony here in another similar question

This is the official list. However, you're recommended not to use --harmony because it enables all the experimental features.

why node.js upgrade version 0.12.x directly to 4.0.0?

  1. io.js was a fork of node.js. The two projects converged recently.

  2. This discrepancy is explained in many different places on the web, including on the nodejs.org in the news section here. Specifically this part of the announcement:

    Named version 4.0.0 because it includes major updates from io.js version 3.0.0

Which EcmaScript 6 features can be translate to ES5 code?

Most new language features can be transpiled (as transpilers like Babel and TypeScript prove). Additions to the standard library can generally be polyfilled.

What you can't transpile, however, are features like tail call optimization because they would require modifications to the JavaScript engine itself.

Also, you can't subclass built-in constructors like Array or Error. Finally, proxies can neither be 100% transpiled nor polyfilled. Pretty much all other ES6 features, though, can be lowered to ES5 (including generators, which can be turned into state machines).

Check out the ES6 compatibility table for an exhaustive overview of all features that are supported by various transpilers.

Is it possible to use generators in node v0.12.0?

As noted by aarosil, an asterisk is needed.. and you need the --harmony flag. Also, see this question for ES6 features supported in 0.12.0: ECMAScript 6 features available in Node.js 0.12

"use strict";

function* simpleGenerator(){
yield "first";
yield "second";
yield "third";
for (var i = 0; i < 3; i++)
yield i;
}


Related Topics



Leave a reply



Submit