边缘:SCRIPT1028:期望的标识符,字符串或数字 [英] Edge: SCRIPT1028: Expected identifier, string or number

查看:424
本文介绍了边缘:SCRIPT1028:期望的标识符,字符串或数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面在Chrome和Firefox中运行良好:

My page works fine in Chrome and Firefox:

但是,当我尝试在Edge中加载此页面时,问题和答案消失了.仅类别被发布.另外,当尝试在IE中加载此页面时,除搜索栏外,所有内容都会消失.

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给我以下错误:

Edge gives me the following error:

SCRIPT1028:SCRIPT1028:faq.html的第84行上的预期标识符,字符串或数字

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

这是指以下代码:

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;
  }, {});
}

我该如何解决?

推荐答案

(令人惊讶的是)似乎Edge还不支持属性休息,这是不幸的,但是后来才正式在ES2018中添加.您需要重写代码以不使用属性剩余(对象文字的...rest部分)(或如 CertainPerformance建议的那样,请使用转译器).

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;
    }, {});
}

我避免使用delete,因为对象上的delete会取消优化该对象,从而使属性查找变慢.但是,仅对这些对象进行优化可能不会对您的页面/应用程序的感知速度产生任何影响,所以...

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...

这篇关于边缘:SCRIPT1028:期望的标识符,字符串或数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆