ECMAScript6 is the next generation standard of JavaScript. It aims to enable JavaScript to write complex applications, function libraries, and Automatic Code generators (codegenerator ). Enable ES6 (harmony) in NodeJS:
Start,
Enable in Linux
Source: http://h3manth.com/new/blog/2013/es6-on-nodejs/
Node version: v0.11.6
Let's take a look at the version harm ;):
$ node --v8-options | grep harm --harmony_typeof (enable harmony semantics for typeof) --harmony_scoping (enable harmony block scoping) --harmony_modules (enable harmony modules (implies block scoping)) --harmony_symbols (enable harmony symbols (a.k.a. private names)) --harmony_proxies (enable harmony proxies) --harmony_collections (enable harmony collections (sets, maps, and weak maps)) --harmony_observation (enable harmony object observation (implies harmony collections) --harmony_typed_arrays (enable harmony typed arrays) --harmony_array_buffer (enable harmony array buffer) --harmony_generators (enable harmony generators) --harmony_iteration (enable harmony iteration (for-of)) --harmony_numeric_literals (enable harmony numeric literals (0o77, 0b11)) --harmony_strings (enable harmony string) --harmony_arrays (enable harmony arrays) --harmony (enable all harmony features (except typeof))
Yes. We can use awk to enable all the new ES6 features, which must be used with strict.
$ node --use-strict $(node --v8-options | grep harm | awk '{print $1}' | xargs) #ES6
Enable in Windows (common method)
Source: http://stackoverflow.com/questions/13351965/what-does-node-harmony-do
node --harmony app.js
Let's look at an example.
Scope
The keyword let allows us to limit the scope of the variable to a code block.
'use strict';if (1) { let b = 2; console.log(b); //2}console.log(typeof b); //undefined