Is it possible to make Polyfill for Arrow Function and Template String?

Asked

Viewed 124 times

4

The functionality of Template String and Arrow Function are excellent to facilitate some Javascript operations. However, it seems that not all browsers still support the same.

In many cases of lack of support for new functions, such as Object.assign, it is possible to make a Polyfill.

But in the case of Template String and Arrow Function? It would be possible to do some Polyfill?

I wonder this because it is related to Language Syntax.

Would there be some way to use these two excellent features in browser versions that do not yet have support?

  • You could use Babel: <https://babeljs.io/setup> It will convert your code that contains Arrow functions and template strings to code that supports older browsers. I don’t think it is possible to use a polyfill because you would have a syntax error. Babel will compile your code so it will make the necessary syntax transformations.

  • 2

    When the question is interpreter, there is no way to insert a function for such (case of Shim/polyfill), in this case only transpillators.

  • @Gabrielheming, that’s the doubt I was in. I heard comments that had Polyfill for this in Javascript, but the person may have confused Polyfill with transpilation.

  • Unless there is a way for Javascript to parse Javascript itself to transform into another valid Javascript :D

  • @Wallacemaxters There is, and that’s what Babel does. It’s even possible to do it in Runtime, but not recommended for obvious reasons.

1 answer

1

I recommend you do not resort to Polyfills in this case, use the Babel, for he is not only one transpilador ES6 (ES2015). The ECMA standards committee has agreed to release annual updates to the Javascript language. Babel will always use the standards, while we do not know if all browsers will do it, and if they will be able to keep up with the changes.

Using a transpilador like the Babel, you don’t care about browsers, in the matter of using the new features of Ecmascript when they are released, rather than waiting for browser manufacturers to integrate the features or use polyfills.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.