taniarascia / comments

Comments
7 stars 0 forks source link

understanding-destructuring-rest-spread/ #29

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Understanding Destructuring, Rest Parameters, and Spread Syntax | Tania Rascia

This article was originally written for DigitalOcean. Introduction Many new features for working with arrays and objects have been made…

https://www.taniarascia.com/understanding-destructuring-rest-spread/

riazXrazor commented 4 years ago

very insightful thanks !!

prashanthaKumar commented 4 years ago

It's a very informative article

Lcfvs commented 4 years ago

Nice article but misses 2 useful tricks:

console.log(value) // 1

 * **arguments skipping**
```js
function getThird(...[,,third]) {
  return third
}

console.log(getThird(1, 2, 3)) // 3
alexleduc76 commented 4 years ago

When needing immutability, I find the spread syntax overly verbose compared to this:

deepCopy = (obj) => { return JSON.parse(JSON.stringify(obj)) }

Lcfvs commented 4 years ago

@alexleduc76 Except that: your deep copy doens't preserves the methods, prototypes chain, map, etc.

alexleduc76 commented 4 years ago

@Lcfvs That's true, however I have never had a need to deep copy anything but objects and arrays containing primitive values.

alexleduc76 commented 4 years ago

(except nested array and objects of course.)

rolandoivan23 commented 3 years ago

Thank you, great post.