I have a function makeThings(n) that returns a Promise to create n number of items (through Sequelize).
It was suggested to me to use this format for retrieving values:
const [thing1, thing2] = yield makeThings(2);
I can't find anything on the internet about assigning constants/variables in this way. Have you seen this? How does it work? My machine doesn't like it and spits out an unexpected token "[" error.
Maybe it might be a npm package that I don't know about?
Using Node.js 5.1.0, ES6
This is a thing in ES6. It's called "Destructuring Assignment"
ECMAScript 6
var list = [ 1, 2, 3 ]
var [ a, , b ] = list
[ b, a ] = [ a, b ]
ECMAScript 5
var list = [ 1, 2, 3 ];
var a = list[0], b = list[2];
var tmp = a; a = b; b = tmp;
It's from http://es6-features.org/#ArrayMatching. It's a pretty good site to get introduced to some of the new features in es6.
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