– Node.js中的和谐标志0.12抛出SyntaxError
所以我写了以下内容:
index.js
let x = 31 console.log(x)
并试着用--harmony
标志进行testing:
alex@alex-K43U:~/node/es6$ node --harmony index.js
但是我得到一个错误:
/home/alex/node/es6/index.js:1 (function (exports, require, module, __filename, __dirname) { let x = 31 ^ SyntaxError: Illegal let declaration outside extended mode
我究竟做错了什么? 我已经更新到节点0.12.1
。
您需要启用严格模式才能使用let
。
你可以:
"use strict" let x = 31 console.log(x)
要么:
node --harmony --use_strict index.js
然后它按预期工作:
victor@ubuntu:~/Documents$ node --harmony --use_strict index.js 31