Syntax error in IE using ES6 arrow functions

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?

Answers


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?


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.


Need Your Help

Add "Watermark" effect with CSS?

css

I have an image in a div. I need to add a watermark effect, or basically another image, overtop the image the div. How can I do this with css?

UIAlertView button action?

ios objective-c delegates uialertview

I have an UIAlertView that shows with this code that asks you to rate the application in the appstore.