I have a pattern that i have an global array and whenever it requires processing move it to a local array and manipulate it so as to keep the original array intact. It had tended to work well until now.
function updateSpend(dataspend,year){
// moving data spend global spend
// the value data spend itself is created from another Global attribute in //
// calling class. Something like this **var loc = Object.create(spend);**
globalSpend = dataspend;
// After the subsequent for loop the value of the original reflects the change
dataspend.forEach(function(d){
var val = d.values.filter(function(d){
if(d.key === year.key)
return false;
return true;
});
d.values = val;
})
var UpdateSvg =
d3.selectAll(".rects")
.data(dataspend);
//UpdateSvg.exit().remove();
var rectsAll = UpdateSvg.selectAll("rect")
.data(function(d){
return d.values
});
rectsAll.exit().remove();
rectsAll.append("rect");
//UpdateSvg.exit().remove();
}
I checked numerous SO posts on how array assignment is a pass by reference and also tried Object.create and other options still the global array is getting reflected. Are there any operators to keep them independent?
Thanks, Veera