Javascript/Jquery Internet Explorer 中的错误

Javascript/Jquery Errors in Internet explorer

我的大部分编程工作都是使用 chrome 调试我的网站,最近在 Internet Explorer 中查看了结果。我得到的错误没有出现在 chrome 中。我相信我在堆栈溢出时从其他接受的答案中获得了这些代码片段中的每一个。他们可以得到任何帮助,我们将不胜感激。我确实做了一些研究,Internet Explorer (11) 解决方案对我来说不是立竿见影的

图片中的错误都是因为IE不支持ES6/ES7语法。如果你需要Internet Explorer 11中的ES6功能,请查看Babel. Here's an article之类的转译器如何使用babel将ES6转换为ES5,请查看。

  1. Arrow function:

您应该使用 Bable 转译它或更改如下语法:

function sleep(ms) {
  return new Promise(function (resolve) {
    return setTimeout(resolve, ms);
  });
}
  1. Promise:

你可以参考 about making promise work in IE. You could use a 3rd party promise library like Bluebird.

  1. Object.entries():

您需要添加 polyfill 才能在 IE 11 中运行:

if (!Object.entries) {
  Object.entries = function( obj ){
    var ownProps = Object.keys( obj ),
        i = ownProps.length,
        resArray = new Array(i); // preallocate the Array
    while (i--)
      resArray[i] = [ownProps[i], obj[ownProps[i]]];
    
    return resArray;
  };
}
  1. async function:

您可以使用 facebook/regenerator 在 IE 11 中填充 async/await。

You could follow the steps to support async/await in IE 11:

  • use babel-preset-env
  • yarn add regenerator or npm install regenerator
  • add node_modules/regenerator-runtime/runtime.js (10.7kb minified) into your bundle

参考link:Add ES7 Async/Await Support for your Webapp in 3 Easy Steps