Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My page works fine in Chrome and Firefox: enter image description here

However, when I try to load this page in Edge, the questions and answers disappear. Only the categories are posted. Also, when trying to load this page in IE, everything disappears except for the search bar.

Edge gives me the following error:

SCRIPT1028: SCRIPT1028: Expected identifier, string or number on line 84 of faq.html

This refers to the following code:

function sortByCategory(data) {
  return data.reduce((obj, c) => {
    const { category, ...rest } = c; // this line throws the error
    obj[category] = obj[category] || [];
    obj[category].push(rest);
    return obj;
  }, {});
}

How do I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
500 views
Welcome To Ask or Share your Answers For Others

1 Answer

It appears (surprisingly) that Edge doesn't support property rest yet, which is unfortunate but then it was officially added only in ES2018. You'll need to rewrite the code not to use property rest (the ...rest part of your object literal) (or, as CertainPerformance suggests, use a transpiler).

Here's one of many ways to do that:

function sortByCategory(data) {
    return data.reduce((obj, c) => {
        //const { category, ...rest } = c;
        const { category } = c;
        const rest = {};
        for (const key of Object.keys(c)) {
            if (key !== "category") {
                rest[key] = c[key];
            }
        }
        obj[category] = obj[category] || [];
        obj[category].push(rest);
        return obj;
    }, {});
}

I avoided using delete because delete on an object de-optimizes the object, making property lookups slower. But deoptimizing just these objects may well not make any difference to the perceived speed of your page/app, so...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...