I’m using a javascript library called d3 in order to perform some animations on an object. At the end of each animation I want to call a function which is passed data from the object which called the animation, but it’s not working. How do I accomplish this? Here’s my code:
function selectArcs() {
d3.selectAll("g.arc > path")
.each(arcTween)
}
function arcTween(d,i){
console.log(i); //registers as 0, then 1
d3.select(this)
.transition().duration(1000)
.attrTween("d", tweenArc({ init : d.value }))
.each("end",function(i){ console.log(i); }); //registers as 0, then 0 - should be 0, then 1
}
In
function(i){ console.log(i); }You’re calling the parameteribut it’s actually what would commonly be calledd!Try replacing it with
function(dOrWhatever){ console.log(i); }(this should get theivariable fromfunction arcTween(d,i))