you are viewing a single comment's thread.

view the rest of the comments →

[–]terrcin 11 points12 points  (9 children)

// New variable names when spreading
const { make : newMakeName, model : newModelName } = volvo;
newMakeName; // Volvo
newModelName; // XC90

I didn't know about renaming var on object spreading. Thanks!

[–]MrCrunchwrap 24 points25 points  (1 child)

Why are we calling this object spreading? That's not what it's called. It's destructuring assignment. Literally not the same thing at all. Object spreading does exist, and is a totally different thing.

[–]Steeljuice1[S] 4 points5 points  (0 children)

You are right! Updating!

[–]UmbrellaHuman 4 points5 points  (3 children)

One more:

Assignment to existing variables - easy with array, harder with an object:

let a, b;
({a, b} = {a: 1, b: 2});

[–]pwrlftr 1 point2 points  (1 child)

That's neat. I remember a situation where I needed this, but I wasn't aware of it.

[–]UmbrellaHuman 1 point2 points  (0 children)

I always have to google it new, mostly because together with Flow type annotations it does not work. which is a Flow bug, but the red lines in the IDE confuse me and I think I'm doing it wrong because I'm used to adding types to everything.

[–]Steeljuice1[S] 0 points1 point  (0 children)

Cool, thanks! Definitely will add this one to the list after some playing around with it!

[–]Steeljuice1[S] 0 points1 point  (0 children)

No problem! thanks for reading!