3

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

$ node -v                                                                      
v5.5.0

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

Where did I do it wrong?

2 Answers 2

2

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

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

Does not work but...

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

does work, when using the --harmony_destructuring.

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

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.

Sign up to request clarification or add additional context in comments.

4 Comments

It already works in node master and thus will be in the upcoming node v6.0.0.
Thank you Alex, I thought enabling the v8 flag could enable me to learn the new feature easy comparing to testing in browser.
Nit: it wasn't a bug, it's just that despite looks, destructuring (binding) and destructuring assignment are entirely separate features (in terms of both language spec and implementation), and V8 shipped the former first. The latter followed behind the --harmony-destructuring-assignment flag.
Or you can upgrade to Node 6.5v
1

Destructure is broken.

In progress features can be activated individually by their respective harmony flag (e.g. --harmony_destructuring), although this is highly discouraged unless for testing purposes.

https://nodejs.org/en/docs/es6/ and this answer Destructuring in Node.JS

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.