4 ms·
The point is apparent is you use actual use cases. let {title, content, email} = articles[0]; let [all, ident, domain] = email.match(/[^@]*@.*/); return
by arcatek 11y ago
The point is apparent is you use actual use cases.
let {title, content, email} = articles[0];
let [all, ident, domain] = email.match(/[^@]*@.*/);
return `<h1>${title} (${ident} at ${domain})</h1><p>${content}</p>`;
Secondly, there is no destructor in JS (because of dynamic memory management), and there will probably never be. Destructuring is nothing like destructors.
Thirdly, the language doesn't have to fork. You can still write ES5 code. But you should probably not because, believe it or not, ES2015 is a really good thing, full of improvements. And syntaxic sugars are part of what makes using it so much nicer than ES5.
- z3t4 11y agoArticles 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!
- woah 11y agoSo.... How would a lack of destructuring avoid this? You would still have two undefined variables, plus a bit more typing.
- z3t4 11y agoIt 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);
- tracker1 11y agoI 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!"