等效于IE的箭头功能 [英] Equivalent of arrow functions for IE

查看:53
本文介绍了等效于IE的箭头功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个在Google Chrome浏览器中运行良好的程序,但我刚刚意识到它在IE中存在问题. IE指出这是由于使用箭头功能引起的语法错误,因为最新的IE不支持它们.谁能告诉我如何更改我的代码以使其能够在IE上运行?

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);

      }

    });

}

推荐答案

我可能会丢失一些内容,但是在快速浏览一下代码之后,只有这一行似乎使用了任何ES6语法:

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

.then((value) => {

只需将其更改为:

.then(function(value) {

如果您有更多的代码,并且不想手工删除此类引用,那么@jonrsharpe提出的编译器建议是一个很好的建议.

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.

这篇关于等效于IE的箭头功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆