“箭头功能”不在IE工作,为什么? [英] "Arrow function" not working in IE, why?
本文介绍了“箭头功能”不在IE工作,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面一段代码在IE 11中不起作用,它在控制台中抛出语法错误
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"));
使用 d3.js
二分图进行可视化
此代码导致上述陈述中的问题 d =>(d.part ==primary?-40:40)
this code causing the issue in above statement d=>(d.part=="primary"? -40: 40)
推荐答案
您正在使用箭头功能。 IE11不支持它们。改为使用函数
函数。
You're using arrow functions. IE11 doesn't support them. Use function
functions instead.
这是 Babel's 将其翻译成ES5:
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";
});
这篇关于“箭头功能”不在IE工作,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文