在Node8中,使用和声选项在v8中进行数组解析赋值 [英] Array destructuring assignment not working in v8 with harmony option in Node.js

查看:111
本文介绍了在Node8中,使用和声选项在v8中进行数组解析赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何在Node中启用和声v8选项,而我的节点版本是:

I want to learn how to enable harmony v8 options in Node, and my node version is:

$ node -v                                                                      
v5.5.0

使用ES6解构作为测试的例子

Use ES6 destructuring as an example for testing

$ cat destructure.js
'use strict'
var a, b
[a, b]  = [1, 2] 
console.log(a, b)

直接运行得到错误如预期的那样。

Run it straight gets error as expected.

$ node destructure.js 
/usr/home/mko_io/pure-js-files/destructure.js:3
[a, b]  = [1, 2]
^^^^^^

但是在标志设置完成后会收到相同的错误:

But get the same error, after the flag has been set:

$ node --harmony_destructuring destructure.js 
/usr/home/mko_io/pure-js-files/destructure.js:3
[a, b]  = [1, 2]
^^^^^^

ReferenceError: Invalid left-hand side in assignment

我在哪里它错了?

推荐答案

显然这是V8 JavaScript引擎中的错误。

Apparently this is/was a bug in the V8 JavaScript engine.

'use strict'
var a, b
[a, b]  = [1, 2] 
console.log(a, b)

无效但...

'use strict'
var [a, b]  = [1, 2] 
console.log(a, b)

在使用 - harmony_destructuring 时可以正常工作。

does work, when using the --harmony_destructuring.

看起来实验功能尚未完全符合规范。

Looks like the experimental feature is not yet fully spec-compliant.

V8的相关错误报告将此问题标记为2015年12月修复,所以现在我们只需要等待更新的V8使其进入Node。 @mscdex 已通知我,此修复程序将在Node v6.0.0中可用。

The relevant bug report for V8 marked this issue as fixed in December 2015, so now we just need to wait for the updated V8 to make it into Node. @mscdex has informed me this fix will be available in Node v6.0.0.

这篇关于在Node8中,使用和声选项在v8中进行数组解析赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆