Is it safe to use the new syntactic sugar for Javascript callbacks?

3

These days I was testing some Javascript features in Google Chrome 50 and I noticed that it has already been added to arrow function for callbacks.

So:

$.each([1, 2, 3], x => x * 2);

// [2, 4, 6]

Formerly it would have to do like this:

$.each([1, 2, 3], function (x) { return x * 2; })

Can we safely use this option for all browsers (we're in 2016!), or do I still have to wait a little bit longer?

    
asked by anonymous 24.05.2016 / 19:49

1 answer

8

It's not safe. ECMAScript 6 is not receiving 100% feature support even in browsers (even the modern ones), and even if the latest browser version supports these features you will limit the way your site works for those browsers. The ideal thing is to program with features of ECMAScript 5, I am an adept at this idea, although there are people who use other techniques for the code to run with ECMAScript 3. Everything depends on your audience, generally the support for ECMAScript 5 is essential .

You can follow the browser support and much more here: link

And if you still want to use ECMAScript 6, look for other alternatives like Babel, Traceur, Webpack ...

In this personal project of a friend I recently did a branch where I rejuvenated all the code for ES6. I use Webpack with Babel in this project and it works in old browsers because the code is transpiled to ES5.

link

    
24.05.2016 / 20:02