You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IE兼容问题:箭头函数替代方案咨询

Fixing IE Syntax Error from Arrow Functions

Hey there, the issue you're hitting is that Internet Explorer (even IE11) doesn't support ES6 arrow functions (() => {}), which is why you're seeing that syntax error. Let's fix this by replacing all arrow functions in your code with traditional function expressions.

Here's how to adjust your removeRow function to be IE-compatible. I'll assume there were arrow functions in the SweetAlert callback (since that's a common spot for them):

Original (IE-incompatible) code snippet (with assumed arrow function):

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: "rollback" 
      } 
    } 
  }).then((value) => { 
    // Your logic using the input value
    if (value === "rollback") {
      // Handle rollback case
    } else if (value) {
      pro = value;
      // Rest of your code here
    }
  });
}

Modified (IE-compatible) version:

function removeRow(a, ref, plt, pcs, loc, trk, din) { 
  var pro; 
  // If you need to access `this` inside the callback, store it in a variable first
  var self = this; 
  swal("Enter the shipment's tracking information:", { 
    content: "input", 
    buttons: { 
      cancel: true, 
      roll: { 
        text: "Don't have it", 
        value: "rollback" 
      } 
    } 
  }).then(function(value) { 
    // Your logic using the input value
    if (value === "rollback") {
      // Handle rollback case
      // If you need `this` here, use `self` instead (since regular functions have their own `this`)
    } else if (value) {
      pro = value;
      // Rest of your code here
    }
  });
}

Key changes to note:

  • Replaced the arrow function (value) => { ... } with a regular function(value) { ... }
  • Added var self = this; at the top of the function if you need to reference the original this context inside the callback (arrow functions inherit this from their parent, but regular functions don't—so storing it in a variable fixes that)

Bonus tips for broader IE compatibility:

  • Replace any const or let declarations with var (IE doesn't support block-scoped variables)
  • Avoid template literals (`string ${var}`) — use string concatenation instead ("string " + var)
  • For larger projects, consider using a transpiler like Babel to automatically convert ES6+ code to ES5, which saves you from manually fixing each compatibility issue

Make sure to test the modified code directly in IE to catch any other potential issues. Hope this helps!

内容的提问来源于stack exchange,提问作者Carlos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:21:42