Well, I've got your point, and changed my code to var data =
jQuery.extend(true, [], arrComp);
With that, I wanted to make a copy of "arrComp" into "data", so that
deleting something in data won's mess with arrComp, right?
Testing like you did (and even if I make arrComp.toSource() , copy the
cont
> x[1] = {twist: 3};
> alert( x.toSource() ); // [{test:1}, {twist:3}]
My test case was broken! When I change it to this:
var x = [ {test:1}, {toast:2} ];
var y = $.extend(true, [], x);
x[1].toast = 3;
alert( y.toSource() );
I get the expected output:
[{test:1}, {toast:2}]
That is, x was deep-
> var data = jQuery.extend(true, {}, arrComp);
You're extending an Array into an empty Object? That would lose the
Array-ness of the original object. I don't think this is a use case
that was ever anticipated, not sure it makes sense.
You could extend into an empty array [] to fix that, but after