如何使用ES5解构阵列?

问题描述

很难将此行转换为ES5,希望有人可以提供帮助:

function([i,o]) { return line(i.path(o)); }

我们托管代码的系统显然不喜欢将数组作为参数分解,因为它是ES6的功能,但我不确定如何将其转换为ES5。

这是该行所在的整个命令:

const link = svg.append("g")
  .attr("stroke",colornone)
  .attr("fill","none")
  .selectAll("path")
  .data(root.leaves().flatMap(function(leaf) { return leaf.outgoing; }))
  .join("path")
  .style("mix-blend-mode","multiply")
  .attr("d",function([i,o]) { return line(i.path(o)); }) // <----               
  .each(function(d) { d.path = this; });

任何帮助将不胜感激!

解决方法

用一个变量替换它:

 function( array ) {

然后逐个提取每个属性。

 var i = array[0];
 var o = array[1];