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.

ES7 Array and Generator comprehensions

38 pointsby mdibaieealmost 10 years ago

4 comments

zaiusalmost 10 years ago
While I really like comprehensions, as soon as you need a conditional, or any level of nesting, you pretty much have to break it out into a loop to keep it readable.<p>OTOH, block syntax (I don&#x27;t think that&#x27;s the correct term for it) has always irked me in JS, due to verbose function declaration, and no implicit return. So beautiful syntax in ruby like:<p><pre><code> some_array.map { |el| el.length } # Or the succinct version: some_array.map(&amp;:length) </code></pre> Looks like this in JS:<p><pre><code> someArray.map(function() { return this.length; }); </code></pre> Now that ES6 has arrow functions with implicit returns, we can do this:<p><pre><code> someArray.map( s =&gt; s.length ); </code></pre> Since both comprehensions and implicit return functions are being released around the same time, I&#x27;ll be interested to see which of the two gets more adoption.
评论 #9683063 未加载
aidosalmost 10 years ago
Nice to see generator comprehensions in js. Glad that I don&#x27;t have to remember anything much when coming from Python due to the choice of &#x27;(&#x27;.<p>Does anyone know where the for..of syntax comes from? Just seems to deviate from the way that other languages represent comprehensions (including maths).
评论 #9683956 未加载
colandermanalmost 10 years ago
This is bizarre to me. Why complicate the browser with a feature that amounts to syntactic sugar?<p>Why not keep JS simple (or better yet, simplify it further!) so that browser implementations might finally converge, and leave the syntactic niceties to preprocessors &amp; compilers?
评论 #9683802 未加载
taco_emojialmost 10 years ago
I read about stuff like this and then wonder whether I&#x27;ll ever be able to use it since target browser platforms are so fragmented.
评论 #9682824 未加载