简体   繁体   中英

Javascript/Jquery Errors in Internet explorer

I've done most of my programming debugging my website with chrome and recently took a look at the results in Internet explorer. The errors I'm getting do not show up in chrome. I believe I got each of these code snippets from other accepted answers here on stack overflow. Any help they can be given would certainly be appreciated. I did do some research and the Internet explorer (11) solution was not immediate for me

睡觉

核心价值

异步

The errors in the pictures are all due to IE doesn't support ES6/ES7 syntax. If you require ES6 features in Internet Explorer 11, check out a transpiler such as Babel . Here's an article about how to use babel to convert ES6 into ES5, please check it out.

  1. Arrow function :

You should transpile it using Bable or change the syntax like below:

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

You could refer to this thread about making promise work in IE. You could use a 3rd party promise library like Bluebird .

  1. Object.entries() :

You need to add a polyfill for it to work in 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 :

You can use facebook/regenerator to polyfill async/await in IE 11.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM