Internet Explorer 在以下行中引发错误并退出处理:How do I fix it?

Internet explorer throws an error and quits processing on the following line: How do I fix it?

let timerId = setInterval(() => { thisisanewguy = "true"; }, 1000);

 if (thisisanewguy != "true") {
                    if (popup == "false") {
                        if (cancelled2 != "true" && $('[id$=div_contactinfo]').length == 0 && $('[id$=div_specpopup]').length == 0 && $('[id$=familymold]').length == 0 && $('[id$=div_load]').length == 0 &&
                            $('[id$=painting]').length == 0 && $('[id$=printing]').length == 0 && $('[id$=customprocess]').length == 0 && $('[id$=insert]').length == 0 &&
                            $('[id$=assembly]').length == 0 && $('[id$=addpart2]').length == 0 && $('#div_background2').css("display") != "block" && $('#div_background').css("display") != "block" && $('#lightbox').css("display") == "none") {
                            setTimeout(function () {
                                if (!mouseEnter && cancelled2 != "true" && thisisanewguy != "true") {
                                    $('#alldone').css("display", "block");
                                    $('#div_background2').css("display", "block");
                                }
                            }, 5000);
                        }
                        else if ($('[id$=div_contactinfo]').length > 0) {
                            let timerId = setInterval(() => { thisisanewguy = "true"; }, 1000);
                            // after 10 seconds stop
                            setTimeout(() => { clearInterval(timerId); thisisanewguy = "false"; }, 10000);
                        }
                    }
                }

其他浏览器当然没问题。我们今天发现 IE 在这里跌倒了。而且我还没有想出如何解决它。我们 8% 的客户仍在使用 IE。

我看到您在代码中使用了 => Internet Explorer 不支持的箭头函数。

看这里...

参考:

Arrow functions

要解决此问题,您需要将代码从 ES6 转换为 ES5。

您可以使用 Babel 来转译您的代码。

这是使用 Babel 的转译代码示例。

"use strict";

if (thisisanewguy != "true") {
  if (popup == "false") {
    if (cancelled2 != "true" && $('[id$=div_contactinfo]').length == 0 && $('[id$=div_specpopup]').length == 0 && $('[id$=familymold]').length == 0 && $('[id$=div_load]').length == 0 && $('[id$=painting]').length == 0 && $('[id$=printing]').length == 0 && $('[id$=customprocess]').length == 0 && $('[id$=insert]').length == 0 && $('[id$=assembly]').length == 0 && $('[id$=addpart2]').length == 0 && $('#div_background2').css("display") != "block" && $('#div_background').css("display") != "block" && $('#lightbox').css("display") == "none") {
      setTimeout(function () {
        if (!mouseEnter && cancelled2 != "true" && thisisanewguy != "true") {
          $('#alldone').css("display", "block");
          $('#div_background2').css("display", "block");
        }
      }, 5000);
    } else if ($('[id$=div_contactinfo]').length > 0) {
      var timerId = setInterval(function () {
        thisisanewguy = "true";
      }, 1000); // after 10 seconds stop

      setTimeout(function () {
        clearInterval(timerId);
        thisisanewguy = "false";
      }, 10000);
    }
  }
}