TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Destructuring Assignment in ECMAScript 6

123 pointsby mnemonikalmost 12 years ago

13 comments

kevincennisalmost 12 years ago
For anyone interested in trying some of this stuff out (which I highly recommend, because a lot of the new stuff in ES6 is really great), Google has an awesome tool called Traceur [<a href="https://github.com/google/traceur-compiler" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;traceur-compiler</a>] that will compile ES6 into ES5.<p>There&#x27;s also an online version here: [<a href="https://github.com/google/traceur-compiler" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;traceur-compiler</a>] that&#x27;s great for quick little experiments. And, as an added bonus, it encodes your script in the URL so you can share it.
评论 #6219527 未加载
mrspeakeralmost 12 years ago
This, and the short function syntax (that&#x27;s also already in Firefox stable: &quot;let square = x =&gt; x * x&quot;) make me very giddy. It&#x27;s always been possible to write JavaScript in a functional style - but this kind of sugar makes it much much nicer. Things like Traceur will even let us transpile to old-school JS for old browser support, so for a lot of projects we can start using these things real soon.
评论 #6219411 未加载
santialboalmost 12 years ago
For anyone wondering, TypeScript will also include support for this <a href="http://typescript.codeplex.com/workitem/15" rel="nofollow">http:&#x2F;&#x2F;typescript.codeplex.com&#x2F;workitem&#x2F;15</a>
STRMLalmost 12 years ago
This is great and allows us to do some slicker functional code:<p><pre><code> function take(num, list) { if (num &lt;= 0 || !list || list === []) return []; var [head, ...tail] = list; return [head].concat(take(num - 1, tail)); } </code></pre> It&#x27;s not as elegant as haskell but it&#x27;s still nicer than it would be without the new syntax.<p>Once we have support for tail call optimization, things will get really interesting.
评论 #6221881 未加载
scribualmost 12 years ago
Yet another great feature heavily inspired from CoffeeScript (and tastefully expanded upon). Well done!<p>The surprising thing for me is that destructuring _almost_ allows defining default values for function arguments.
评论 #6219793 未加载
评论 #6222634 未加载
评论 #6219651 未加载
xhrpostalmost 12 years ago
Definitely looking forward to this as well as other new ES6 stuff. There&#x27;s something else I feel I could use perhaps even more but I haven&#x27;t seen it in any of the ES* updates. I&#x27;m a huge advocate of DRY and it bothers me when I have to code something like:<p><pre><code> var a = objImUsing.prop.someLongName &gt; 5 ? objImUsing.prop.someLongName : whatever; </code></pre> I can and sometimes just make an extra variable above for a long prop list like this but that adds an extra line. I guess what I would like would be some sort of implied line limited scope:<p><pre><code> var a = objImUsing.prop.someLongName &gt; 5 ? _1 : whatever; </code></pre> _1 referring to the first mentioned value in the immediate parent statement.
评论 #6220181 未加载
评论 #6222318 未加载
agentultraalmost 12 years ago
I can see why Brendan Eich is excited to get ES6 out there. It&#x27;s finally coming back around to parity with Scheme. I&#x27;m looking forward to seeing more.
评论 #6219664 未加载
评论 #6222249 未加载
评论 #6221020 未加载
Spoomalmost 12 years ago
PHP has this available as list[1] in a slightly more limited form.<p>1. <a href="http://php.net/list" rel="nofollow">http:&#x2F;&#x2F;php.net&#x2F;list</a>
评论 #6221001 未加载
评论 #6220720 未加载
评论 #6220202 未加载
cldralmost 12 years ago
Good to see, this is one thing I have really missed from Erlang when writing Javascript.
评论 #6219835 未加载
crazygringoalmost 12 years ago
That&#x27;s awesome.<p>Any bets on when we can start using it on the front-end? I&#x27;m sure Chrome&#x2F;FF will pick it up quick once it&#x27;s finalized, but when will ECMAScript 6 be present in 95% of IE installations? 2020?
评论 #6223333 未加载
NKCSSalmost 12 years ago
With the Destructuring Objects, I was like: WTF, but it all makes sense once you get to the Practical Applications of Destructuring. Nice stuff.
评论 #6223954 未加载
marshrayalmost 12 years ago
Who needs ML when now we have Javascript?<p>I never thought I&#x27;d hear myself say that. But seriously, this is awesome. Thank you, whomever!
kclayalmost 12 years ago
This is nice, reminds me of Scala