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.

Xto6 modernizes your JavaScript code

87 pointsby atriixover 9 years ago

15 comments

daliwaliover 9 years ago
Most ES6 features are either equal to or worse than their ES5 counterparts in terms of performance, some by orders of magnitude (!)<p>For example, `class` has particularly bad performance characteristics because under the hood it has to set an object&#x27;s prototype on the fly (at least this is how Babel implements it) [1] and `super` is also slow due to prototype lookup [2].<p>[1] <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;setPrototypeOf" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Refe...</a><p>[2] <a href="https:&#x2F;&#x2F;jsperf.com&#x2F;es6-classes-super-es5-vs-transpiled&#x2F;2" rel="nofollow">https:&#x2F;&#x2F;jsperf.com&#x2F;es6-classes-super-es5-vs-transpiled&#x2F;2</a>
评论 #10737073 未加载
评论 #10738771 未加载
评论 #10738049 未加载
评论 #10737069 未加载
KenanSulaymanover 9 years ago
Always getting &#x27;app.js:22 Uncaught TypeError: Cannot set property &#x27;kind&#x27; of undefined&#x27; :-(<p>However, I doubt that I would use it - most of the &#x27;modernizations&#x27; are really dependent on the context of each change and require some tweaking.<p>For instance, ES6 classes do not allow for inline computed methods:<p><pre><code> const x = function () {}; x.prototype.a = wrapFunction(function(){}); </code></pre> --- this is impossible: ---<p><pre><code> class x { a() wrapFunction(function(){}); &#x2F;&#x2F; invalid :-( } </code></pre> So we&#x27;re still required to use the explicit prototype way of declaring the class.<p>Then you can&#x27;t just rewrite all methods to arrow functions because they don&#x27;t have prototypes, even when they&#x27;re really tempting:<p><pre><code> var x = function () {}; x.prototype.a = &lt;foo&gt;; </code></pre> ---&gt;<p><pre><code> var x = () =&gt; {}; x.prototype.a = &lt;foo&gt;; &#x2F;&#x2F; cannot set a of undefined </code></pre> ...<p>$0.02
评论 #10737613 未加载
joostersover 9 years ago
Your working javascript can now be transformed into slower, more incompatible code that might not work! Yaaaaaaaay.
评论 #10737631 未加载
tantalorover 9 years ago
Wow, the example is atrocious,<p><pre><code> Person.prototype.getAge = function (birthYear) { var age = 2015; age -= birthYear; return result; &#x2F;&#x2F; Do you mean return age? }; Object.defineProperty(Person.prototype, &#x27;age&#x27;, { get: function () { return this.getAge(); &#x2F;&#x2F; getAge function takes a required parameter. } });</code></pre>
khgvljhkbover 9 years ago
Javascript sure got more features, but how many should Crockford add to &quot;the good parts&quot;? If you ask me, only generators.
评论 #10737974 未加载
评论 #10737445 未加载
评论 #10737592 未加载
评论 #10737596 未加载
josteinkover 9 years ago
Trying some simple this-based class&#x2F;instance-construction in the constructor leads to the whole thing failing:<p><pre><code> var Person = function (name) { console.log(&#x27;This is the constructor.&#x27;); var _name = name; this.getName = function() { return _name; }; }; </code></pre> Since this is 1 of the 2 patterns for creating classes, and the only one which supports encapsulation, it seems like a strange omission.<p>Especially so if the goal is to migrate &quot;old&quot; javascript to get it &quot;modern&quot;. Migrating bleeding edge JS to even more bleeding edge JS hardly seems like a very worthwhile endeavour.
juhqover 9 years ago
Could this be used to improve current ES5 codebases by converting to ES6 and then use Babel to convert back to (improved?) ES5?
评论 #10737942 未加载
davejover 9 years ago
Watch out for lexical binding with arrow functions. It could lead to some nasty bugs if you blindly transpile your old code.
评论 #10736883 未加载
lollipop25over 9 years ago
It&#x27;s not like your JS won&#x27;t run on ES6 browsers. That&#x27;s the whole point of backwards compatibility. Besides, older features will probably have better performance as they have been tuned for years, compared to newer features.<p>People in the JS world should seriously drop the NIH syndrome and contribute to existing tools instead. The last thing we&#x27;d ever need is yet another framework&#x2F;library&#x2F;tool that&#x27;s just a bit more than what&#x27;s already existing.<p><a href="http:&#x2F;&#x2F;www.isaacchansky.me&#x2F;days-since-last-new-js-framework&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.isaacchansky.me&#x2F;days-since-last-new-js-framework&#x2F;</a>
z3t4over 9 years ago
I would also recommend: <a href="https:&#x2F;&#x2F;github.com&#x2F;alcuadrado&#x2F;hieroglyphy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alcuadrado&#x2F;hieroglyphy</a>
评论 #10738166 未加载
pedalpeteover 9 years ago
I don&#x27;t see this as a real benefit to update your code, but maybe as a learning tool to see how your code would be implemented using es6.<p>I like to take a wait-and-see on these language updates to see which parts get widespread adoption. I find the most important part at this point isn&#x27;t the features, but having code that the majority of developers can understand.
dyejeover 9 years ago
Demo box felt claustrophobic. I pasted in code and nothing appeared on the other side. An error message would have been nice. Ah well, I&#x27;ll probably check this out again after a while.
merbover 9 years ago
i would like a es6 to es3 compiler. When working with legacy devices it&#x27;s a real mess, especially when you are used to sometimes use console.log..
joewrongover 9 years ago
can someone explain where &quot;result&quot; comes from in their examples?
tehbeardover 9 years ago
It&#x27;s neat to see a competitor to babel, but man that colour scheme is suspiciously similar.
评论 #10736913 未加载
评论 #10736911 未加载
评论 #10737213 未加载
评论 #10736906 未加载
评论 #10737154 未加载