7

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?

user229044
  • 222,134
  • 40
  • 319
  • 330
Michael Tot Korsgaard
  • 3,702
  • 10
  • 51
  • 87

2 Answers2

21

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?

Community
  • 1
  • 1
roberrrt-s
  • 7,624
  • 2
  • 45
  • 55
4

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.

Val Berthe
  • 1,661
  • 1
  • 16
  • 33