【问题标题】:Using a destructuring assignment to iterate over an es6 map with nodejs 4.1.2使用解构赋值通过 nodejs 4.1.2 迭代 es6 映射
【发布时间】:2017-04-09 17:15:52
【问题描述】:

我尝试像here 描述的那样迭代 es6 映射:

for (var [key, value] of myMap.entries()) {
  console.log(key + " = " + value);
}

当我使用 nodejs 4.1.2 和 --harmony 标志运行它时

SyntaxError: Unexpected token [

我会写

for (var arr of myMap.entries()) {
  console.log(arr[0] + " = " + arr[1]);
}

但这并不好,因为它没有表现力。

有没有更好的办法?

【问题讨论】:

  • 您是否尝试过明确使用--harmony_destructuring 标志?
  • 它适用于这个标志

标签: node.js


【解决方案1】:

这个回答是按照this meta post做的。


因为@Ben Fortune 有commented:

您是否尝试过明确使用 --harmony_destructuring 标志?

很难找到有关此标志的实际文档,但可以在 GitHub issue 中找到有关节点 4 中的解构分配的更多信息。

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2020-05-19
    • 2019-07-11
    • 2020-07-13
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多