如何使用ECMAScript 6在node.js v4.2.1中

3
我尝试使用 let 时出现以下情况:
(function (exports, require, module, __filename, __dirname) { let i = 0;
                                                              ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:134:18)
    at node.js:961:3

我听说v4已经支持ECMAScript 6,不需要babel。

1个回答

5

您需要使用严格模式(请参见您的错误消息)才能使用ES6功能:

"use strict";
let yourcode = "here";

编辑:感谢@user5448026的提醒,我在这里完全搞砸了。


1
"use strict"; 运行正常,但是 "strict mode" 却没有。 - user5448026

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接