Equivalent of arrow functions for IE

此生再无相见时 提交于 2020-01-15 06:55:18

问题


I wrote a program that works well in Google Chrome, but I just realized that it is having problems in IE. IE states that this is due to a syntax error given by the use of arrow functions since they are not supported in the latest IE. Can anyone tell me how to change my code to be able to run it on IE?

function removeRow(a, ref, plt, pcs, loc, trk, din) {

  var pro;

  swal("Enter the shipment's tracking information:", {
      content: "input",
      buttons: {
        cancel: true,
        roll: {
          text: "Don't have it",
          value: " ",
        },
        confirm: {
          text: "Submit",
        }
      }
    })
    .then((value) => {

      pro = value;
      //console.log(pro);

      if (pro !== null || pro === ' ') {

        b = '#' + a;
        c = '#H' + a;

        var d = new Date();
        var n = Math.round(d.getTime() / 1000);

        var table = $('#mytable')
          .DataTable();

        // Remove a row by Id:
        table.row(b)
          .remove()
          .draw();

        var url = "delete.php"; // the script where you handle the form input.

        $.ajax({
          type: "POST",
          url: url,
          data: {
            id: a,
            track: pro,
            dateout: n
          },
          success: function(data) {
            //alert(data); // show response from the php script.
            //console.log('Success!');
          }
        });

        swal("Success", "Shipment was entered successfully!", "success");

        if (ref == '') {

        }

        var t = $('#myhistory').DataTable();

        t.row(c)
          .remove()
          .draw();

        var reference = ref;
        var pallets = plt;
        var pieces = pcs;
        var location = loc;
        var carrier = trk;
        var datein = din;
        var dateout = n;
        var rowid = 'H' + a;

        if (datein.length < 12) {

          var month = datein.toString().substring(0, 1);

          if (month == '01') {
            month = 'Jan';
          } else if (month == '02') {
            month = 'Feb';
          } else if (month == '03') {
            month = 'Mar';
          } else if (month == '04') {
            month = 'Apr';
          } else if (month == '05') {
            month = 'May';
          } else if (month == '06') {
            month = 'Jun';
          } else if (month == '07') {
            month = 'Jul';
          } else if (month == '08') {
            month = 'Aug';
          } else if (month == '09') {
            month = 'Sep';
          } else if (month == '10') {
            month = 'Oct';
          } else if (month == '11') {
            month = 'Nov';
          } else if (month == '12') {
            month = 'Dec';
          }

          var day = datein.toString().substring(1, 3);
          var year = datein.toString().substring(3, 7);
          var hour = datein.toString().substring(7, 9);
          var second = datein.toString().substring(9, 11);

        } else {

          var month = datein.toString()
            .substring(0, 2);

          if (month == '01') {
            month = 'Jan';
          } else if (month == '02') {
            month = 'Feb';
          } else if (month == '03') {
            month = 'Mar';
          } else if (month == '04') {
            month = 'Apr';
          } else if (month == '05') {
            month = 'May';
          } else if (month == '06') {
            month = 'Jun';
          } else if (month == '07') {
            month = 'Jul';
          } else if (month == '08') {
            month = 'Aug';
          } else if (month == '09') {
            month = 'Sep';
          } else if (month == '10') {
            month = 'Oct';
          } else if (month == '11') {
            month = 'Nov';
          } else if (month == '12') {
            month = 'Dec';
          }

          var day = datein.toString().substring(2, 4);
          var year = datein.toString().substring(4, 8);
          var hour = datein.toString().substring(8, 10);
          var second = datein.toString().substring(10, 12);
        }

        var tout = new Date();
        var timeout = tout.toString();
        var monthout = tout.toString().substring(4, 7);
        var dayout = tout.toString().substring(8, 10);
        var yearout = tout.toString().substring(11, 16);
        var hourout = tout.toString().substring(16, 18);
        var secondout = tout.toString().substring(19, 21);

        var dateout = monthout + ', ' + dayout + ' ' + yearout + ' at ' + hourout + ':' + secondout;

        var datein = month + ', ' + day + ' ' + year + ' at ' + hour + ':' + second;

        t.row.add([
            reference,
            pallets,
            pieces,
            location,
            carrier,
            datein,
            dateout,
            pro
          ])
          .node()
          .id = rowid;
        t.draw(false);

      }

    });

}

回答1:


I could be missing something, but after a quick skim of your code, only this line appears to use any ES6 syntax:

.then((value) => {

Simply change it to:

.then(function(value) {

If you have much more code and don't want to remove such references by hand, @jonrsharpe's suggestion of a transpiler is a good one.



来源:https://stackoverflow.com/questions/50241267/equivalent-of-arrow-functions-for-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!