norman784 norman784 - 3 months ago 23
Node.js Question

Harmony destructuring ReferenceError: Invalid left-hand side in assignment

This a weird behaviour, i've tested on Chrome and works just fine without any flag, but in node it doesn't work event with the latest version

$ node --harmony_destructuring app.js

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

$ node -v

v5.11.0


Any clues on why it doesn't work or a version of node in witch works?

Thanks

Answer

The correct syntax would be

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

You can read more on destructuring here.

Comments