Chirag Patel
Chirag Patel

Reputation: 5939

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 Developer Tools console

Upvotes: 0

Views: 2874

Answers (1)

bigless
bigless

Reputation: 3111

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

Upvotes: 1

Related Questions