admin管理员组文章数量:1295783
I have this piece of JavaScript code
price = price.replace(/(.*)\./, x => x.replace(/\./g,'') + '.')
This works fine in Firefox and Chrome, however IE gives me an syntax error pointing at =>
in my code.
Is there a way to use ES6 arrow syntax in IE?
I have this piece of JavaScript code
price = price.replace(/(.*)\./, x => x.replace(/\./g,'') + '.')
This works fine in Firefox and Chrome, however IE gives me an syntax error pointing at =>
in my code.
Is there a way to use ES6 arrow syntax in IE?
Share Improve this question edited Oct 18, 2016 at 13:57 user229044♦ 239k41 gold badges344 silver badges346 bronze badges asked Oct 18, 2016 at 13:46 Michael Tot KorsgaardMichael Tot Korsgaard 4,01411 gold badges56 silver badges93 bronze badges 2 |2 Answers
Reset to default 21IE 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?
Internet explorer doesn't support arrow functions yet. You can check the browsers supporting arrow functions here.
The method to solve it would be to make a good old regular callback function :
price = price.replace(/(.*)\./, function (x) {
x.replace(/\./g,'') + '.';
}
This would work in every browser.
本文标签: javascriptSyntax error in IE using ES6 arrow functionsStack Overflow
版权声明:本文标题:javascript - Syntax error in IE using ES6 arrow functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738477092a2088925.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
replace
. – Wiktor Stribiżew Commented Oct 18, 2016 at 13:47