Comment on ES6 in Depth: DestructuringparentComments−z3t411yArticles should already be an associative array in the first place.I can understand why you think the email example looks better, but whoops, there's a bug, you now got two undefined variables!−tracker111yI believe in this case articles[0] is pulling a specific article (object) from an array of objects, then destructuring that instance.. articles.forEach(article => { let { title, content, email } = article; ... }) Might have made that more clear... but .forEach is an ES5 addition...Given the backlash with ES6, I wonder why we didn't see this with ES5... "OMG they added extra sugar to Array.prototype, we're all gonna die!"−woah11ySo.... How would a lack of destructuring avoid this? You would still have two undefined variables, plus a bit more typing.−z3t411yIt would probably have looked like this: var email = article.email, at = email.indexOf("@"), ident = email.substr(0, at), domain = email.substring(at + 1, email.lengt);
Comments
Articles should already be an associative array in the first place.
I can understand why you think the email example looks better, but whoops, there's a bug, you now got two undefined variables!
I believe in this case articles[0] is pulling a specific article (object) from an array of objects, then destructuring that instance..
Might have made that more clear... but .forEach is an ES5 addition...Given the backlash with ES6, I wonder why we didn't see this with ES5... "OMG they added extra sugar to Array.prototype, we're all gonna die!"
So.... How would a lack of destructuring avoid this? You would still have two undefined variables, plus a bit more typing.
It would probably have looked like this: