SCRIPT1006: Expected ')'

前端 未结 4 1920
星月不相逢
星月不相逢 2021-02-19 16:44

In the function below, IE says that \')\' is missing:

function padZeros(num, size = 4) {
    var s = num+\"\";
    while (s.length < size) {
        s = \"0\"         


        
4条回答
  •  一生所求
    2021-02-19 17:19

    The issue is that Internet Explorer does not understand "default values for arguments" - this is ES2015+ and since development for IE stopped a long time ago, there's no way the new fangled ES2015+ syntax will ever work for IE

    Try using a transpiler like babel for example until IE officially dies!

    function padZeros(num) {
        var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
    
        var s = num + "";
        while (s.length < size) {
            s = "0" + s;
        }
        return s;
    }
    

提交回复
热议问题