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.

Ask HN: If you targetting ES6 by default, how did you rationalize that choice?

61 pointsby tcrewsover 8 years ago

26 comments

hzooover 8 years ago
Might be a good chance to suggest using our new preset: <a href="https:&#x2F;&#x2F;github.com&#x2F;babel&#x2F;babel-preset-env&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;babel&#x2F;babel-preset-env&#x2F;</a>.<p>TL;DR - automate your Babel config options based on targets.<p>babel-preset-env: A Babel preset that can automatically determine the Babel plugins and polyfills you need based on your supported environments.<p>It takes the data from compat-table [1] to generate a mapping [2] between a Babel plugin and the first version that a browser&#x2F;env supports. We calculate the least common denominator of your targeted envs to determine the final set of plugins to compile with.<p>(Feel free to ask questions, I help maintain Babel and the preset). Just released a 1.0 a few weeks ago and looking for more help and usage! Looking into more help with removing unnecessary polyfills, and determining plugins based on performance via benchmarks of native&#x2F;compiled.<p>And yes there is a lot of work that goes into making this work correctly (and in the foreseeable future with ES2015+). Would appreciate any help moving forward. And maybe we should just replace&#x2F;recommend this preset instead of anything else to fight the fatigue..<p>[1]: <a href="https:&#x2F;&#x2F;kangax.github.io&#x2F;compat-table&#x2F;es6&#x2F;" rel="nofollow">https:&#x2F;&#x2F;kangax.github.io&#x2F;compat-table&#x2F;es6&#x2F;</a> [2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;babel&#x2F;babel-preset-env&#x2F;blob&#x2F;master&#x2F;data&#x2F;plugins.json" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;babel&#x2F;babel-preset-env&#x2F;blob&#x2F;master&#x2F;data&#x2F;p...</a>
Klathmonover 8 years ago
* It makes the language much easier to work with<p>* Most people familiar with JS will pick up on them very easily<p>* It makes &quot;patterns&quot; like immutable data and some straightforward async code MUCH easier (object spread, async&#x2F;await, etc...)<p>* node.js supports it (with a slight speed penalty, however it hasn&#x27;t bottlenecked us yet so we aren&#x27;t worrying about it yet)<p>* Most modern browsers support many of the features, and those that don&#x27;t the polyfills and compilation is pretty much &quot;drop in&quot; with the rest of our build system.<p>* Dead code elimination has completely changed how we architect our projects for the better<p>* const gives us less bugs by preventing overwriting and scope confusion<p>* One of the main applications we are using it on only supports newer browsers that support ES6 natively anyway (due to needing certain browser APIs), so using the full extent of those browsers doesn&#x27;t seem like it&#x27;s going to cause any issues.<p>and finally...<p>* There doesn&#x27;t seem to be any downside. We are only using stuff which is already in the spec, or close enough to being finalized that we are comfortable. If performance is an issue we can just not use it in performance critical code, and it&#x27;s just nicer to work with.<p>I will say that it&#x27;s not all daisies and roses though. We are worried what will happen if the module loading spec goes in another direction than we think it will, not to mention that interfacing with external ES6 libraries is either done through transpiled common-js code (which loses most of the benefits of ES6), or through &quot;hacky&quot; solutions like a &quot;nonstandard&quot; field in the package.json which lets something like webpack load the ES6 version (which we have no idea what features they are using, might need transpiled, might need fixed, etc...).<p>Like anything, it&#x27;s a bit of a gamble. But I&#x27;m confident that we will save more time and have less bugs by using the new features than we will lose to fixing modules to be inline with the spec or dealing with incompatibility problems.
评论 #13238534 未加载
randomfoolover 8 years ago
Broken windows theory- ES6 code is more elegant to look at, which encourages people to write prettier code.<p>Working on a team of experienced non-browser devs, ES6 syntax allowed them to take the language seriously and actually try to do the right thing rather than &#x27;commit atrocities of Javascript&#x27; (actual statement).
alangpierceover 8 years ago
I think the word &quot;target&quot; in the question is unclear, or at least has been misinterpreted. Many of the answers here seem to be about why you would write your source code in ES6, but at least to me, the &quot;target&quot; code is the code that actually ends up executing (whether on the server or in the user&#x27;s browser or whatever).<p>I think it all depends on your context and use case. If you&#x27;re running code on the server, there&#x27;s no reason to compile down to ES5 if you know that your node version can run your code without modification. At my company, we write browser-based tools for scientists, so we have a bit more flexibility in asking users to use modern browsers. We still use babel and target ES5, but we may move off of it before normal consumer websites do.
评论 #13239165 未加载
TheCorehover 8 years ago
IMO, you should set up an analytics funnel to measure landing page conversion or (for web apps) usage metrics based on browser version.<p>Whenever the cost of supporting old, ES5-only browsers (measured by the amount of time spent debugging&#x2F;adapting code * dev hourly rate) surpasses the income brought in by users on those browsers, it&#x27;s probably time to make the switch.<p>For the web app case, you obviously don&#x27;t want to just cut out access to those users (that would be pretty bad customer service! that can totally ruin your reputation), so you also need to factor in the costs of educating your users about the upgrade, giving them enough time and&#x2F;or providing an alternative means of using your app. (ex: an Electron-based app installer)<p>Considering how good the polyfills and transpilers currently are (assuming you already have those set up) the maintenance costs of supporting ES5 are very low. It makes very little financial sense to not support it for existing applications ATM.<p>If you&#x27;re just starting with an app, that is going to launch in one year or more (assuming you&#x27;re focused on a general audience , instead of a specialized market like corporate where browsers are updated more slowly) then I&#x27;d probably already start without worrying about ES5 at all.
评论 #13239097 未加载
评论 #13239270 未加载
Raphmediaover 8 years ago
The code that I write will still be used in 5 years.<p>I can write ES6, stick babel.js on it and my code will be both present-proof and future-proof.
dpwebover 8 years ago
As someone who writes ALOT of vanilla JS and doesn&#x27;t really get into the new fangled frameworks, tools, transpiling..<p>Two things: template strings and arrow functions. Async is life-changing, but lack of support - can&#x27;t use it yet.. Greatest feature since XMLHttpRequest IMO.
gtf21over 8 years ago
Presumably you mean in the browser, rather than node.js? When you can compile and use polyfills with babel and webpack, then why not?
评论 #13238577 未加载
tlrobinsonover 8 years ago
By &quot;targeting ES6&quot; do you mean writing ES6 and transpiling to ES5, or actually shipping ES6 to browsers?
评论 #13239611 未加载
simlevesqueover 8 years ago
My code runs on Node &gt;6.9.1 so it&#x27;s really a no-brainer. The synthax is clearly superior.
评论 #13239736 未加载
andrenotgiantover 8 years ago
Chrome Extensions! Writing Chrome Extensions is a great way to use all the latest and greatest javascript for a practical project.
benologistover 8 years ago
I limit myself to ES6 features supported by Node LTS on the server-side.<p>I limit myself to ES5 code on the client side for now and probably at least next year too.<p>By writing code that is compatible with the platform it runs on I&#x27;m able to avoid having a slow, lengthy or complex build process to reach that state.
lobster_johnsonover 8 years ago
Not to nitpick, but the word &quot;rationalize&quot; usually has a negative connotation — to rationalize something is to attempt to justify&#x2F;explain something that wasn&#x27;t a rational choice to begin with [1]. In short, you&#x27;re implying that people&#x27;s decision to use ES6 wasn&#x27;t based on a conscious, analytical decision.<p>If that&#x27;s not what you meant, perhaps &quot;justify&quot; would be a better word to use. Or maybe just: &quot;Why?&quot;<p>[1] <a href="https:&#x2F;&#x2F;www.merriam-webster.com&#x2F;dictionary&#x2F;rationalize" rel="nofollow">https:&#x2F;&#x2F;www.merriam-webster.com&#x2F;dictionary&#x2F;rationalize</a>
modularfurniturover 8 years ago
How would you rationalize not using ES6?
评论 #13239330 未加载
charrondevover 8 years ago
I&#x27;m working on something that will be solely an electron app, so I&#x27;m using typescript and targeting ES6. Besides the bundling, the resulting code looks very similar to the typescript code minus the types.
tal_berznizover 8 years ago
If you want to attract the best talent and not lose the good engineers you already have, keeping up with the times is a must. ES6 is one major advancement for front-end developers and they want to be part of it
k__over 8 years ago
By not caring about IE11?<p>You simply have to ask yourself, who do you want to sell your stuff to.<p>If you got a rather technical audience for example, chances are hight that most of them are using current browsers. So you simply develop for them and get a very simple build process, which eliminates many potential bug sources.<p>If you want to sell to Siemens, Bosch, Daimler. Chances are hight that they use IE11.<p>You can also start building for current browsers and if too many people complain or you get the feeling that you lose too much users by ignoring IE, you simply add Babel or something.
SimeVidasover 8 years ago
I’m about to start coding my site from scratch using ES6 module + async&#x2F;await syntax. I’m doing it because it will improve readability, which in turn will make the code more maintainable.
tannhaeuserover 8 years ago
I&#x27;ll be waiting till async&#x2F;await (ES7 maybe?) is available natively in browsers and node.js and its error handling story is cleaned up. Right now, in node.js if you&#x27;re using streams2&#x2F;3, it&#x27;s quite the mess to recover gracefully already. Future of exception domains in node.js isn&#x27;t clear to me either. Also, browsers aren&#x27;t there yet either (eg. Fetch API error handling and aborting).
grandalfover 8 years ago
In a nutshell, the js community is doing a great job of moving the language forward, and there is a great deal of cost to be borne by using the oldest version of the language that all browsers support. Browser vendors (in general) are the laggards, but there is an easy enough way to work around them.<p>ES6 also nudges the code toward a bit more uniformity that can lead to better medium term maintainability.
WorldMakerover 8 years ago
I&#x27;m going to use Typescript regardless of which flavor of ES&#x2F;JS I expect to target, for type safety alone. Since I&#x27;m already using a build system, writing for the latest ES&#x2F;JS spec supported by Typescript is entirely about convenience of the new specs themselves. I can use Typescript to downlevel as necessary for the expected runtime environments.
ggregoireover 8 years ago
Am I the only one to not understand the question?
评论 #13238902 未加载
评论 #13238829 未加载
spankaleeover 8 years ago
Recently I&#x27;ve been advocating a move to distributing uncompiled ES6 packages, and shipping ES6 to browsers that support it and compiling using a single simple preset (ES2015 except modules).<p>There are several big reasons:<p>1) ES5 &quot;classes&quot; cannot extend ES6 classes (it&#x27;s not possible to emulate a super() call in ES5), so:<p>1a) All the extendable built-ins are basically ES6 classes. If you want to extend Array, Map, Set, HTMLElement, Error, etc. you really should use ES6, and deal with emulating extending those classes in the compilation step.<p>1b) Really useful patterns, like ES6 mixins ( <a href="http:&#x2F;&#x2F;justinfagnani.com&#x2F;2015&#x2F;12&#x2F;21&#x2F;real-mixins-with-javascript-classes&#x2F;" rel="nofollow">http:&#x2F;&#x2F;justinfagnani.com&#x2F;2015&#x2F;12&#x2F;21&#x2F;real-mixins-with-javascr...</a> ) don&#x27;t work when ES5 and ES6 versions are mixed in a prototype chain. That is, an ES6 mixin, compiled to ES5, can&#x27;t be applied to an ES6 superclass. So if you distribute ES5 you&#x27;re forcing everything above you on the prototype chain to be ES5.<p>2) It&#x27;s much easier to debug uncompiled code, and all major browsers (as of Firefox 51) and node support ES6 well. Shipping uncompiled ES6 is a dream to work with comparatively.<p>3) ES6 is a much better compilation target for things like async&#x2F;await because of generators.<p>4) ES6 is easier to statically analyze, so tools like TernJS and TypeScript (which can do analysis of regular JS too) can give better completions, etc.<p>5) It makes the pipeline from source -&gt; packaging -&gt; depending -&gt; building for deployment much simpler.<p>Packages shouldn&#x27;t assume too much about their eventual environment. That used to mean not assuming that the environment had ES6 or things like Promises. But times change and now that all the current environments support ES6, packages shouldn&#x27;t assume that environments _don&#x27;t_ support it.<p>So packages shouldn&#x27;t directly depend on polyfills that most current environments have (Promise, Object.assign, new Array methods, etc.). Instead they should target standard ES6 and let the app developer who knows what they&#x27;re targeting choose the necessary polyfills and down compilation. There&#x27;s really too much bloat from packages forcing the inclusion of multiple Promise polyfills, or versions of core-js.<p>Also, it used to be that compiling dependencies was a major pain. You&#x27;d likely have to write custom build rules that compile and stage each dependency - because each dependency might have different language features and polyfill they might use. Now the packagers like WebPack and Rollup are so good at finding all dependencies statically, and we have a new stable plateau of language features in ES6, that the packager can compile everything it needs.<p>Of course if you use features beyond ES6, then those should be compiled to ES6. This implies a rule of thumb to move forward: Once all major browsers and node LTS have a feature, start assuming that feature and don&#x27;t compile it out. For example, once Firefox and node LTS get the exponentiation operator, start distributing ES2016 (see <a href="http:&#x2F;&#x2F;kangax.github.io&#x2F;compat-table&#x2F;es2016plus&#x2F;" rel="nofollow">http:&#x2F;&#x2F;kangax.github.io&#x2F;compat-table&#x2F;es2016plus&#x2F;</a> ).
seanwilsonover 8 years ago
I&#x27;m using Typescript. The amount of bugs it catches (e.g. undefined&#x2F;null errors and unexpected string&#x2F;number bugs being the biggest ones) makes it more than worth it.
评论 #13242451 未加载
griffinmichlover 8 years ago
On personal projects? babel-preset-stage-0 #yolo
angelmmover 8 years ago
Hello! I assume you are talking about we development.<p>As a developer, the new versions of EcmaScript include good features that make easier the development of our applications. Also, ES6 is not a beta, it&#x27;s a new version of the language. We are talking about frontend, so the execution environment of our application is unknown. However, the benefits of using the new features are big.<p>For me, the most important one is the new methods on basic types. With old versions of EcmaScript, I needed to rely in third party libraries to add some functionalities to my project. With the new versions of ES, my code is more independent from external sources.<p>Also, Babel provides backward compatibility for old versions of the language. As I mentioned, we don&#x27;t know the execution environment of our project, but the TC39, the committee behind the decisions of the new features, has thought in this. Adding backward compatibility is a requirement for new features in the language.
评论 #13239219 未加载