Why doesn't this arrow function work in IE 11?
You're using arrow functions. IE11 doesn't support them. Use function
functions instead.
Here's Babel's translation of that to ES5:
g.selectAll(".mainBars").append("text").attr("x", function (d) {
return d.part == "primary" ? -40 : 40;
}).attr("y", function (d) {
return +6;
}).text(function (d) {
return d.key;
}).attr("text-anchor", function (d) {
return d.part == "primary" ? "end" : "start";
});
Since none of the code uses this
, you don't have to worry about preserving arrow function this
behavior (since traditional functions get their this
by how they're called, but arrow functions close over this
). But if the code did use this
and you wanted it to behave like an arrow function would, you'd want to use the usual techniques for that.
ES6 arrow (= ) functions incompatible with IE?
IE11 doesn't support several ES6 features, including lambda functions and template literals.
A rough equivalent that should work is:
myApp.run(function(EventTitle, moment) {
EventTitle.weekView = function(event) {
return moment(event.startsAt).format('hh:mm') + " " + event.title;
};
});
However, there are some ways in which arrow functions do not work in the same way as regular functions. You'll need to watch for the use of this
keywords, for example.
Alternatively, if you use a transpiler like Babel (or a transpiled language like TypeScript), you can use newer language features like your original code, and automatically generate JavaScript code that will run in browsers that don't support those features.
Syntax error in IE using ES6 arrow functions
IE doesn't support ES6, so you'll have to stick with the original way of writing functions like these.
price = price.replace(/(.*)\./, function (x) {
return x.replace(/\./g, '') + '.';
});
Also, related: When will ES6 be available in IE?
“Arrow function” in Array.from and forEach does not work in IE 11 it throws a syntax error in the console.how to solve?
function range(start, end) {
//return Array.from(Array(end - start + 1), (_, i) => i + start);
return Array.from(Array(end - start + 1), function(_, i) {return i + start });
}
&
getPageList(totalPages, currentPage, paginationSize).forEach(function(item) {
$("<li>").addClass("page-item")
.addClass(item ? "current-page" : "disabled")
.toggleClass("active", item === currentPage).append(
$("<a>").addClass("page-link").attr({
href: "javascript:void(0)"}).text(item || "...")
).insertBefore("#next-pages");
});
Equivalent of arrow functions for IE
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.
IE 11 Script1002 Array.Filter(x = ...) (Arrow functions)
ie 11 not support arrow functions
try
var selectedRoles = vm.roles.filter(function(x) { return x.id === role.id; });
Related Topics
Convert a JavaScript String in Dot Notation into an Object Reference
Jquery: Return Data After Ajax Call Success
Get Image Data Url in JavaScript
Why Can't I Directly Modify a Component'S State, Really
Why Is the Method Executed Immediately When I Use Settimeout
Onclick or Inline Script Isn't Working in Extension
How to Detect If a Browser Window Is Not Currently Active
How to Return Many Promises and Wait For Them All Before Doing Other Stuff
What Is the Purpose of a Self Executing Function in JavaScript
When Should I Use Arrow Functions in Ecmascript 6
How to Use Unicode-Aware Regular Expressions in JavaScript
Share Data Between Angularjs Controllers
How to Make Setinterval Also Work When a Tab Is Inactive in Chrome
What Is the !! (Not Not) Operator in JavaScript
In JavaScript, Does It Make a Difference If I Call a Function With Parentheses