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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With