【问题标题】:Why I can not start harmony mode by "node --harmony test.js" from command line?为什么我无法通过命令行中的“node --harmony test.js”启动和​​谐模式?
【发布时间】:2015-12-29 18:05:58
【问题描述】:

问题是:

longhao33@hePC:~$ node --harmony test.js 
/home/longhao33/test.js:1
(function (exports, require, module, __filename, __dirname) { let str = 'es666666666666';
                                                              ^^^

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:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

但在以下情况下支持“let”:(好奇怪!)

longhao33@hePC:~$ node --harmony
> let str = 'es66666666666'
undefined
> str
'es66666666666'
  1. 系统:ubuntu 14.04LTS 64bit
  2. node:V4.1.1(由nvm安装,安装在$HOME)
  3. test.js 的内容:

    让 str = 'es666666666666'; 控制台.log(str);

提前谢谢。

【问题讨论】:

    标签: javascript node.js ecmascript-6 ecmascript-harmony


    【解决方案1】:

    您的test.js 顶部缺少'use strict';(如错误消息所示)。

    它在 REPL 中有效,因为 'use strict'; is automatically included during code evaluation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 2012-11-01
      相关资源
      最近更新 更多