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.

Leave a Comment