Syntax error in IE using ES6 arrow functions

前端 未结 2 1938
不知归路
不知归路 2020-11-29 12:10

I have this piece of JavaScript code

price = price.replace(/(.*)\\./, x => x.replace(/\\./g,\'\') + \'.\')

This works fine in Firefox an

相关标签:
2条回答
  • 2020-11-29 12:51

    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?

    0 讨论(0)
  • 2020-11-29 13:07

    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.

    0 讨论(0)
提交回复
热议问题