为什么此箭头功能在IE 11中不起作用? [英] Why doesn't this arrow function work in IE 11?

查看:141
本文介绍了为什么此箭头功能在IE 11中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在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双向图表进行可视化

Using d3.js bipartite chart for visualization

此代码导致上述语句d=>(d.part=="primary"? -40: 40)

推荐答案

您正在使用箭头功能. IE11不支持它们.改用function函数.

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";
});

这篇关于为什么此箭头功能在IE 11中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆