在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))
不錯(cuò),我們可以通過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
看一個(gè)例子
作用域
關(guān)鍵字 let 可以讓我們將變量的作用范圍限定在一個(gè)代碼塊中
'use strict'; if (1) { let b = 2; console.log(b); //2 } console.log(typeof b); //undefined
相關(guān)文章
node.js中使用node-schedule實(shí)現(xiàn)定時(shí)任務(wù)實(shí)例
這篇文章主要介紹了node.js中使用node-schedule實(shí)現(xiàn)定時(shí)任務(wù)實(shí)例,包括安裝方法和4種使用例子,需要的朋友可以參考下2014-06-06Node.js調(diào)用java之node-java問題
這篇文章主要介紹了Node.js調(diào)用java之node-java問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10Node.js使用Koa搭建 基礎(chǔ)項(xiàng)目
時(shí)下前端工程師有很多人比較關(guān)注NodeJs以及express 框架或者Koa 框架之類的新技術(shù)。難得我最近閑時(shí)較多,利用一下舊歷新年尚未正式到來的這片閑暇,也來涉足其中,一窺其中奧妙。2018-01-01socket.io學(xué)習(xí)教程之基礎(chǔ)介紹(一)
socket.io提供了基于事件的實(shí)時(shí)雙向通訊,所以下面這篇文章主要介紹了關(guān)于socket.io的相關(guān)資料,主要介紹了學(xué)習(xí)socket.io的基礎(chǔ)知識(shí),需要的朋友可以參考借鑒,下面來一起看看吧。2017-04-04詳解Node.js中path模塊的resolve()和join()方法的區(qū)別
這篇文章主要介紹了詳解Node.js中path模塊的resolve()和join()方法的區(qū)別,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10使用upstart把nodejs應(yīng)用封裝為系統(tǒng)服務(wù)實(shí)例
這篇文章主要介紹了使用upstart把nodejs應(yīng)用封裝為系統(tǒng)服務(wù)實(shí)例,需要的朋友可以參考下2014-06-06