在NodeJS中啟用ECMAScript 6 -开发者知识库
http://ourjs.com/detail/535db36b4e127cd93a000004
在NodeJS中啟用ES6 (harmony) ,版本:
開始吧,
Linux下啟用
來源: http://h3manth.com/new/blog/2013/es6-on-nodejs/Node version : v0.11.6
先來看一看版本 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))
不錯,我們可以通過awk來啟用所有的ES6新特性,需要跟 strict
一起使用
$ node --use-strict $(node --v8-options | grep harm | awk '{print $1}' | xargs) #ES6
Windows下啟用(通用方法)
來源: http://stackoverflow.com/questions/13351965/what-does-node-harmony-do
node --harmony app.js
看一個例子
作用域
關鍵字 let
可以讓我們將變量的作用范圍限定在一個代碼塊中
'use strict';
if (1) {
let b = 2;
console.log(b); //2
}
console.log(typeof b); //undefined
最佳答案:
本文经用户投稿或网站收集转载,如有侵权请联系本站。