Expected ')' JS error in IE after assignin

2019-04-07 02:34发布

问题:

I wrote the below code in my JS file and IE is giving error for the argument 'searchMap' when I am assigning value for it in the function.

mapping: function (mappingObj,searchMap=false) {
// code 
}

Error is : Expected ')'

回答1:

You're using default parameter. It is a feature of ES6, and currently not yet supported by IE.

I'd suggest to convert your code to ES5, like..

mapping: function (mappingObj, searchMap) {
   if (!searchMap) searchMap = false;
}


回答2:

var searchMap = false;
mapping: function(mappingObj, searchMap) {
    // code
}

mapping(mappingObj, searchMap);