简体   繁体   中英

ES6/ES2015 Javascript incompatibility in old browser (Edge 13, IE11, etc)

I have a Javascript <script> snippet (try here: https://apploitech.github.io/embed-snippets ) that executes document.write(...) , which writes a bunch of html and javascript functions into the DOM.

One of the Javascript functions does this:

 document.addEventListener("DOMContentLoaded", function() { console.log("DOMContentLoaded calling renderJobs"); renderJobs(null, true, 1); }); 

It works great for most browsers (Chrome, Safari, Edge 14/15), but on the following browsers, the message Expected ')' shows up in the IE/Edge Developer Tools console (as shown in screenshot below):

  1. Edge 13 or below
  2. IE11 or below

Any thoughts or best methods to debug? I tried going to char 1499 like the error message shows, but there is nothing there related to a ) . Thanks!

IE 11开发人员工具控制台

Default parameter is part of ES6/ES2015 spec.

Solution:

function createPaginationButton(pagination_bar, page_num, isAppend) {
  if(isAppend === undefined) {
      isAppend = true;
   }
  ...
}

This is original function declaration from your snippet unsupported in older browsers:

function createPaginationButton(pagination_bar, page_num, isAppend = true) {
    console.log("createPaginationButton(): page_num = " + page_num);
    var page_num_box = document.createElement("a");
    page_num_box.innerHTML = page_num;
    ...
    ...
}

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