使用ES6箭头功能的IE中的语法错误 [英] Syntax error in IE using ES6 arrow functions
本文介绍了使用ES6箭头功能的IE中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段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?
推荐答案
p> 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, '') + '.';
});
Also, related: When will ES6 be available in IE?
这篇关于使用ES6箭头功能的IE中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文