Edge: SCRIPT1028: Expected identifier, string or number

前端 未结 4 2048
情话喂你
情话喂你 2020-12-18 19:23

My page works fine in Chrome and Firefox:

However, when I try to load this page in Edge, the questions and answers disappear. Only the categories are posted. Also,

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 20:15

    Neither Edge nor IE support object property rest syntax (though Edge will likely support it eventually). I'd suggest automatically transpiling your code to ES5 with Babel, which will allow you to write in the latest and greatest version of the language, while allowing ancient and incompatible browsers to understand all of your transpiled code. For example, plugging in

    const { category, ...rest } = c;
    

    results in

    "use strict";
    
    function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
    
    var _c = c,
        category = _c.category,
        rest = _objectWithoutProperties(_c, ["category"]);
    

    Doesn't look so pretty, but it can be done automatically.

    One manual way of doing it could be:

    const c = {
      category: 'category',
      foo: 'foo',
      bar: 'bar'
    };
    
    const category = c.category;
    // Object.assign so as not to mutate the original object:
    const rest = Object.assign({}, c);
    delete rest.category;
    console.log(rest);

提交回复
热议问题