Monday, May 20, 2024
164
rated 0 times [  169] [ 5]  / answers: 1 / hits: 117371  / 8 Years ago, mon, october 24, 2016, 12:00:00

Below piece of code does not work in IE 11, it throws a syntax error in the console



g.selectAll(.mainBars)
.append(text)
.attr(x, d => (d.part == primary ? -40 : 40))
.attr(y, d => +6)
.text(d => d.key)
.attr(text-anchor, d => (d.part == primary ? end : start));


Using d3.js bipartite chart for visualization



This code causing the issue in above statement d=>(d.part==primary? -40: 40)


More From » internet-explorer

 Answers
13

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.


[#60302] Thursday, October 20, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;