Enable ECMAScript6 in NodeJS (windos and Linux) _ node. js

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.