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?

2
  • 2
    Until IE wants to become happy, use anonymous method inside replace. Commented Oct 18, 2016 at 13:47
  • 3
    Use a transpiler or write ES5 code in the first place. Commented Oct 18, 2016 at 13:48

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.