Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run ES6 code with arrow functions in Safari?

For some reason, ES6 code that runs well in the current Chrome or Firefox cannot run in Safari - for example, arrow functions. As I know, Safari has ok support for ES6. Is there something that needs to be done?

Example:

var arr = [1,3,5].map((i) => i*i);
console.log(arr);

Or if it is a full .html file:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>

        <script>
            "use strict";

            var arr = [1,3,5].map((i) => i*i);
            console.log(arr);

        </script>
    </body>
</html>

Safari (I am using 9.0.3) keeps on giving SyntaxError: Unexpected token '>'

like image 217
nonopolarity Avatar asked Jan 29 '16 02:01

nonopolarity


People also ask

Does Safari support arrow functions?

Safari browser version 3.1 to 9.1 doesn't supports. Safari browser version 5 and 5.1 partially suppoprts. Safari browser version 10 to 12 doesn't supports JAVASCRIPT Arrow functions.

Is ES6 supported in Safari?

ECMAScript 2015 (ES6) is Fully Supported on Safari 15, which means that any user who'd be accessing your page through Safari 15 can see it perfectly.

Are arrow functions ES6?

Arrow functions are introduced in ES6, which provides you a more accurate way to write the functions in JavaScript. They allow us to write smaller function syntax. Arrow functions make your code more readable and structured.

What does () => mean in JavaScript?

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.


1 Answers

Based on the MDN link, (near the bottom), Safari does not yet support this feature.

like image 168
Krease Avatar answered Oct 09 '22 03:10

Krease