1

I have a Node.js project in which I use ES6 syntax on the server and non-ES6 syntax on the browser side. I have also tried using ES6 syntax on the browser, but then I experienced problems when I visited the website on iPhones, so I switched back to 'old javascript syntax'.

I can, from Bootstrap's code on Github, see that they use ES6 (const, arrow functions, etc.) in the code for Bootstrap v4.

Is it clever to avoid using ES6 syntax until all used browsers support it? I assume that there always will be a few browsers being used that do not support the new syntax, so why would anyone ever dare to move to the new syntax? I know that it will be very few, but since all the stuff that is possible with ES6 is also possible without ES6, I do not see how it can be worth using the new syntax for the cost of losing potential customers on my website.

Do there exist some scripts that can make sure all my visitors' browsers support ES6?

Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • `I assume that there always will be a few browsers being used that do not support the new syntax` erm, welcome to web development where IE still exists. You're worried about ES6 syntax? Well, how about IE8 which does not support ES5 - should we stop using any ES5 stuff? Or how about IE6 which is EVEN WORSE - should we probably just stop using JavaScript? Oh, but IE6 doesn't support some HTML and some CSS. ES6 is nothing new in terms of non-support, really. Use it if you don't care about legacy browsers, otherwise you can transpile it. – VLAZ Sep 25 '16 at 10:01
  • 1
    Using ES6 can increase readability and maintainability of you code. Especially with the arrow functions you can often avoid the `var that = this;` workarounds. For browser you for sure would add a transpiler into your deployment process and you need to take care which es6 functionalities you use, because certain things won't transpile nice e.g. `yield`, `async`, `await` and inheritance, because they either increase your code and/or you might need to include many polyfills for older browsers. But if you choose the used ES6 features wisely then it is a good thing for keeping your code clean. – t.niese Sep 25 '16 at 10:25
  • _"but since all the stuff that is possible with ES6 is also possible without ES6"_ That's not true. – a better oliver Sep 26 '16 at 06:35

1 Answers1

4

Is it clever to avoid using ES6 syntax until all used browsers support it?

Not really. You can transpile it, for instance with babel (that's what Bootstrap v4, which you raise as an example, also does).

In fact you may want to transpile with babel even if you are guaranteed to have a modern JS runtime in use, to use not-yet-even-quite-standardised language features. The point is not new user visible features but programmer productivity which you can boost in many ways with ES6.

You'll find clear instructions of how to transpile browser intended code with babel for instance in this blog post.

since all the stuff that is possible with ES6 is also possible without ES6, I do not see how it can be worth using the new syntax for the cost of losing potential customers on my website.

At the time of writing transpiling is a pretty essential step, unless you know you are writing against a specific JS execution environment (for instance a hybrid web browser / desktop or mobile app that is based on a known version of WebKit / JavaScriptCore).

Using abstractions that hide platform differences has been essential for years also for many APIs now present in practically all modern browsers, especially (but not limited to) older versions of IE, so you'll be transpiling a long time still if for your purposes old browser versions matter. Shouldn't stop you from getting the productivity benefits, though!

mz2
  • 4,672
  • 1
  • 27
  • 47