Syntax error in IE using ES6 arrow functions

前端 未结 2 1960
不知归路
不知归路 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 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.

提交回复
热议问题