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
content and paste directly in my code, like:)

var arrComp = [{name:'One', value:1}, {name:'Two', value:2}];
var data = jQuery.extend(true, [], arrComp);

It works! Deleting something in data won't change arrComp. But in my
real case, it doesn't work! When I delete something in the data, it
deletes from arrComp as well. I don't know how could I show you this,
I've been trying to reproduce this in small scale, but I had no
success.

If it happens to me to find out a better simulation, I will post here
again. Thanks for you help, though!




On Jan 14, 2:44 am, Dave Methvin <dave.meth...@gmail.com> wrote:
> > 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-extended to y and a change to x didn't affect y.
>
> So it seems like that should work. Can you show more of the code?
-- 
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to