如何在Safari中运行带箭头功能的ES6代码? [英] How to run ES6 code with arrow functions in Safari?

查看:194
本文介绍了如何在Safari中运行带箭头功能的ES6代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,在当前Chrome或Firefox中运行良好的ES6代码无法在Safari中运行,例如箭头功能。据我所知,Safari已经支持ES6。有没有什么需要做的?



示例:

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

或者如果它是一个完整的 .html 文件:

 <!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(我正在使用9.0.3)不断发送 SyntaxError:Unexpected令牌'>'

解决方案

根据 MDN链接(接近底部),Safari还不支持此功能。 p>

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 '>'

解决方案

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

这篇关于如何在Safari中运行带箭头功能的ES6代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆