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 regularfunction(value) { ... } - Added
var self = this;at the top of the function if you need to reference the originalthiscontext inside the callback (arrow functions inheritthisfrom their parent, but regular functions don't—so storing it in a variable fixes that)
Bonus tips for broader IE compatibility:
- Replace any
constorletdeclarations withvar(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
相关产品推荐
相关产品推荐

