IE中的箭头函数对应语法是什么?

3

我写了一个在Google Chrome中运行良好的程序,但是我刚刚意识到它在IE中出现了问题。IE指出这是由于使用箭头函数导致的语法错误,因为最新版本的IE不支持它们。有人能告诉我如何更改我的代码以使其能够在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);

      }

    });

}

4
使用 babel 或其他工具,将其转译为更早期的语法。 - jonrsharpe
1
或者改用函数而不是箭头函数。对于那段代码来说并不难。 - epascarello
哇,Babel非常容易使用,立即解决了我的问题!谢谢!@jonrsharpe - Carlos
1
这里几乎没有箭头,应该遵守DRY原则。 - mplungjan
1个回答

2

可能我漏看了些什么,但是经过快速浏览您的代码后,只有这一行似乎使用了ES6语法:

.then((value) => {

只需将其更改为:

.then(function(value) {

如果你有大量的代码,而且不想手动删除这样的引用,那么@jonrsharpe提出的转译器是一个不错的选择。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接