Why Doesn't This Arrow Function Work in Ie 11

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



Leave a reply



Submit