简体   繁体   English

如何使用 ES5 解构数组?

[英]How can I destructure an array using ES5?

Having a hard time converting this line to ES5, hopefully someone can help:很难将此行转换为 ES5,希望有人可以提供帮助:

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

The system we're hosting the code on obviously doesn't like destructuring the array as an argument as it's an ES6 feature, but I'm unsure how to convert it down to ES5.我们托管代码的系统显然不喜欢将数组作为参数解构,因为它是 ES6 功能,但我不确定如何将其转换为 ES5。

Here's the entire command the line is in:这是该行所在的整个命令:

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

Any help would be appreciated!任何帮助,将不胜感激!

Replace it with a single variable:将其替换为单个变量:

 function( array ) {

and then extract each property one by one.然后一一提取每个属性。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM