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.

ES6: The features I'm most excited about

182 pointsby niixalmost 10 years ago

24 comments

ecaronalmost 10 years ago
Wow. I can&#x27;t believe template strings (<a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;template_strings" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a>) aren&#x27;t in this list. I&#x27;m incredibly excited to start having those at my disposal.
评论 #9836189 未加载
评论 #9839439 未加载
spionalmost 10 years ago
I don&#x27;t understand why everyone considers classes controversial. If you look at code in the wild, it already does what classes desugar to: everyone already writes constructor function and attaches properties to their prototypes.<p>At least now with classes, users coming from other languages wont be as tempted to make their own completely incompatible object systems.
评论 #9838133 未加载
评论 #9837807 未加载
评论 #9837994 未加载
akstalmost 10 years ago
My favourite feature is promises, while it doesn&#x27;t add a new syntax and you can probably add a library for it, the fact it&#x27;s standardised makes a world of difference. Now that it&#x27;s standardised<p>1. It will become the common interface for deferred operations and library authors can make assumptions that it&#x27;s there.<p>2. ES7 Async&#x2F;Await will be able to leverage this common interface.
评论 #9836309 未加载
pipeepalmost 10 years ago
Even better: The arrow function example used the statement form of an arrow function, instead of the expression form, which allows you to omit the return:<p><pre><code> &#x2F;&#x2F; using arrow var adder = { num: 2, nums: [1,2,3,4,5], addIt() { return this.nums.map(n =&gt; this.num + n) } }; console.log(adder.addIt()); &#x2F;&#x2F; [3, 4, 5, 6, 7] </code></pre> I&#x27;ll concede that the arrow function is a bit overly complicated, with this, sometimes-optional argument list parenthesis, and object literal&#x2F;function body syntax ambiguity.
AgentMEalmost 10 years ago
The first module example is incorrect:<p><pre><code> &#x2F;&#x2F; myModule.js export function myModule(someArg) { return someArg; } &#x2F;&#x2F; main.js import myModule from &#x27;myModule&#x27;; </code></pre> The import is importing a non-existent default export. Either the export needs to be changed to a default export:<p><pre><code> export default function myModule(someArg) { </code></pre> -or- the import needs to be changed to importing a member:<p><pre><code> import {myModule} from &#x27;myModule&#x27;;</code></pre>
评论 #9836678 未加载
nodesocketalmost 10 years ago
I was just talking to my friend who works at NetFlix on the frontend team about ES6, he is most excited about destructuring `let { name, age, gender } = user;`. I however advocate that the new class syntax is the best part of ES6. Take the following trivial OOP example, which I think reads so much easier a lot like PHP.<p><pre><code> &quot;use strict&quot;; class Vehicle { constructor(name) { this.kind = &#x27;Vehicle&#x27;; this.name = name; } printName() { console.log(this.name); } } class Car extends Vehicle { constructor(name) { super(name); &#x2F;&#x2F;call the parent method with super this.kind = &#x27;Car&#x27;; } } let myCar = new Vehicle(&#x27;Mercedes&#x27;); console.log(myCar);</code></pre>
评论 #9836299 未加载
评论 #9836623 未加载
评论 #9837680 未加载
评论 #9838931 未加载
chjjalmost 10 years ago
ES6 is a mixed bag for me.<p>I&#x27;m against block scope in a way. It&#x27;s semi-useful, but it&#x27;s just sugar. So many features of ES6 seem to be designed for people who don&#x27;t want to bother learning javascript: classes, block scope, arrow syntax, etc. It&#x27;s just trying to shoehorn javascript into the template every other language follows when javascript is <i>not</i> every other language.<p>That being said, I like iterators, weak maps, typed arrays, TCO, and so on.
评论 #9839207 未加载
charriualmost 10 years ago
I&#x27;m a bit worried about ES6 making the language harder to understand.<p>For example, scoping: For backwards compatibility reasons, var has to stay function scoped. But now we also have let, which has different scoping rules. Also, Symbols: [Symbol.iterator]() - what? Why?!<p>On the other hand, stuff like arrow functions, template strings, modules and tail optimization are awesome.
评论 #9837803 未加载
评论 #9839191 未加载
tlrobinsonalmost 10 years ago
I agree with this list completely, but it doesn&#x27;t mention one of the best reasons generators and promises are awesome: async&#x2F;await-style asynchronous programming eliminates callback hell by letting you write asynchronous code as if it were synchronous, including using control structures like conditionals, loops, and try&#x2F;catch.<p>And you can do it in (most) browsers today using a transpiler like Babel and a library like Blurebird, Q, co, or task.js.<p>The rest of the things are nice, but promises&#x2F;generators (and eventually async&#x2F;await) are game-changers.
评论 #9837781 未加载
评论 #9836559 未加载
kriroalmost 10 years ago
I think .bind(this) could be added as a (more common?) alternative example to var self = this;<p>Personally I&#x27;m most excited about the module system. It&#x27;s by far the most confusing thing for our students (and hard to google since you end up going down the rabbit hole of build systems etc.)
评论 #9837213 未加载
评论 #9838935 未加载
qudatalmost 10 years ago
Coroutines are the game changer imo. I wrote a little presentation to illustrate code flow: <a href="http:&#x2F;&#x2F;afc.neurosnap.net" rel="nofollow">http:&#x2F;&#x2F;afc.neurosnap.net</a>
habermanalmost 10 years ago
I&#x27;ve just been playing with Promises and like them a lot. But one thing I find strange is that &quot;.then()&quot; creates a new promise, but with no way to reject it.<p>ie. I can&#x27;t write:<p><pre><code> return new Promise((resolve, reject) =&gt; { &#x2F;&#x2F; Do some stuff, call resolve()&#x2F;reject() on success&#x2F;failure. }).then((step1Val, resolve, reject) =&gt; { &#x2F;&#x2F; Do some stuff, call resolve()&#x2F;reject() on success&#x2F;failure. &#x2F;&#x2F; But this doesn&#x27;t actually work, because the &quot;then&quot; callback &#x2F;&#x2F; doesn&#x27;t get resolve&#x2F;reject as args. }); </code></pre> Instead I&#x27;m having to write this as the following, which is more verbose:<p><pre><code> return new Promise((resolve, reject) =&gt; { &#x2F;&#x2F; Do some stuff, call resolve()&#x2F;reject() on success&#x2F;failure. }).then(new Promise((resolve, reject) = { &#x2F;&#x2F; Do some stuff, call resolve()&#x2F;reject() on success&#x2F;failure. &#x2F;&#x2F; But this way I don&#x27;t get access to step1Val. })); </code></pre> Another bummer of this style is that that the second step doesn&#x27;t get access to the first step&#x27;s value.
评论 #9836564 未加载
评论 #9837621 未加载
评论 #9836569 未加载
评论 #9836311 未加载
评论 #9836225 未加载
评论 #9836235 未加载
评论 #9836599 未加载
评论 #9836233 未加载
joeaxalmost 10 years ago
Although arrow functions are nice, they&#x27;ve been around in the form of lambda expressions in C# and other languages for some time, so the initial reaction was more of a &quot;about time&quot; rather than a &quot;wow!&quot; for me. Same goes for generators&#x2F;yield keyword.<p>Thanks for pointing out the key difference between arrow functions and inline functions being the context of &#x27;this&#x27;. &#x27;this&#x27; is going to be a source of confusion for a lot of people.
评论 #9836983 未加载
pjmlpalmost 10 years ago
Now just throw away the DOM, replace it with something more suitable for applications instead of documents, and we can have something akin to Smalltalk back.
dpwebalmost 10 years ago
Promises I find rather ugly to read. So far Im liking arrow functions and template strings. Async&#x2F;await I&#x27;m looking forward to in ES7.
评论 #9836039 未加载
评论 #9837776 未加载
pubbyalmost 10 years ago
I&#x27;m new to Javascript, and am wondering if I be writing ES6 instead of ES5. Is that a good idea, or should I wait a few months&#x2F;years?
评论 #9836216 未加载
评论 #9837634 未加载
zozalmost 10 years ago
I was a little confused by the constructor for Player in the class example. Wouldn&#x27;t the following be more appropriate:<p><pre><code> constructor(x = 0, y = 0) { this.x = x; this.y = y; } </code></pre> (i.e. this way if &quot;new Archer(&#x27;Legolas&#x27;, 5, 6);&quot; the x and y values will not be ignored.)
评论 #9838943 未加载
koolbaalmost 10 years ago
What&#x27;s the point of promises being part of ES6?<p>I understand them and use them quite a bit. I just don&#x27;t understand why they&#x27;re in the language spec. They don&#x27;t add anything new to the language (<i>vs say generators or symbols</i>).<p>Is it purely for performance?
评论 #9838417 未加载
评论 #9838807 未加载
_pmf_almost 10 years ago
Catching up a bit with C#, I see.
scriptlealmost 10 years ago
The example quoted under &quot;Arrow functions&quot; is NOT &quot;arrow function&quot;. It&#x27;s an enhanced object literal.
评论 #9838919 未加载
chengas123almost 10 years ago
When will browsers start to implement these features? I&#x27;m looking forward to being able to use modules in Chrome.
评论 #9837140 未加载
m1sta_almost 10 years ago
I hope our IDEs get smart enough so that destructuring features result in pseudo named function parameters.
评论 #9841039 未加载
github-catalmost 10 years ago
So will someday there be interface in JavaScript?
andylalmost 10 years ago
I&#x27;ve used ES6 and prefer coffeescript - IMHO more concise, easier to read, and has been place for years.
评论 #9836138 未加载