【问题标题】:Harmony destructuring ReferenceError: Invalid left-hand side in assignmentHarmony解构ReferenceError:分配中的左侧无效
【发布时间】:2016-08-16 15:17:06
【问题描述】:

这是一种奇怪的行为,我已经在 Chrome 上进行了测试,并且没有任何标志就可以正常工作,但是在节点中它不适用于最新版本的事件

$ node --harmony_destructuring app.js

[length, offset] = this.getint(data, offset, 2)
^    
ReferenceError: Invalid left-hand side in assignment

$ node -v

v5.11.0

关于为什么它不起作用或女巫中的节点版本起作用的任何线索?

谢谢

【问题讨论】:

  • 应该是var [length, offset] = this.getint(data, offset, 2)
  • 模块中不能有隐式全局变量。

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


【解决方案1】:

正确的语法应该是

const iterable = ['a', 'b'];
const [x, y] = iterable;

你可以阅读更多关于解构here的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 2018-10-02
    • 2018-06-10
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多