Syntax Error only in IE

2019-07-25 13:40发布

问题:

I get a syntax error only in IE11 on this line and i can't seem to pinpoint what the issue is. Its on line two quizOptions.map((item, i) => {

the error is: SCRIPT1002: Syntax Error (this was the edit)

I haven't seen any issues with this piece of code on any other browser.

var quizOptions = cur_quizInfo.options;
quizOptions.map((item, i) => {
  var li = jQuery("<li>", {
    class: 'quiz_answers',
    text: item
  }).appendTo(buttonList);
});

回答1:

ES6 arrow functions are not supported by Internet Explorer.

You could (probably) replace your example with this:

var quizOptions = cur_quizInfo.options;
quizOptions.map(function(item, i) {
  var li = jQuery("<li>", {
    class: 'quiz_answers',
    text: item
  }).appendTo(buttonList);
});