IE 中使用 ES6 箭头函数的语法错误 [英] Syntax error in IE using ES6 arrow functions

查看:24
本文介绍了IE 中使用 ES6 箭头函数的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段 JavaScript 代码

I have this piece of JavaScript code

price = price.replace(/(.*)./, x => x.replace(/./g,'') + '.')

这在 Firefox 和 Chrome 中运行良好,但是 IE 给了我一个语法错误,指向我的代码中的 =>.

This works fine in Firefox and Chrome, however IE gives me an syntax error pointing at => in my code.

有没有办法在 IE 中使用 ES6 箭头语法?

Is there a way to use ES6 arrow syntax in IE?

推荐答案

IE 不支持 ES6,因此您必须坚持使用原始方式编写此类函数.

IE doesn't support ES6, so you'll have to stick with the original way of writing functions like these.

price = price.replace(/(.*)./, function (x) {
  return x.replace(/./g, '') + '.';
});

另外,相关:什么时候可以在 IE 中使用 ES6?

这篇关于IE 中使用 ES6 箭头函数的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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