在NodeJS中啟用ECMAScript 6小結(jié)(windos以及Linux)
在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
看一個例子
作用域
關(guān)鍵字 let 可以讓我們將變量的作用范圍限定在一個代碼塊中
'use strict';
if (1) {
let b = 2;
console.log(b); //2
}
console.log(typeof b); //undefined
相關(guān)文章
詳解基于node.js的腳手架工具開發(fā)經(jīng)歷
這篇文章主要介紹了詳解基于node.js的腳手架工具開發(fā)經(jīng)歷,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
使用NestJS開發(fā)Node.js應(yīng)用的方法
這篇文章主要介紹了使用NestJS開發(fā)Node.js應(yīng)用的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12
npm一鍵安裝Python以及node-sass依賴環(huán)境的方法
Node-sass是一個庫,它將Node.js綁定到LibSass,下面這篇文章主要給大家介紹了關(guān)于npm一鍵安裝Python以及node-sass依賴環(huán)境的相關(guān)資料,文中還介紹了安裝node-sass報錯Python環(huán)境問題避坑指南,需要的朋友可以參考下2022-09-09

