Ah. You are seeing the intended behavior.

Array.clone is intended to give you back an array that contains all the
items from the original but is otherwise "unlinked". So, for example:

var first = [1, {two: 2}];
var second = first.clone();
second[0] = 2;
second[1].two = 3;

first[0] == 1; //changes to members of the clone are not affected
first[1].two == 2; //changes to objects and arrays that are properties are
unaffected

But what it *doesn't *do is this same behavior for elements. If you look at
the code, you can see that it's only arrays and objects that get this
treatment:

https://github.com/mootools/mootools-core/blob/master/Source/Core/Core.js#L334

This might be considered a bug; you could argue that this check should call
.clone for arrays, objects, or elements, but then you have the issue that
Element.clone takes arguments and all that jazz.

Just do it yourself:

http://jsfiddle.net/D4qNB/2/

On Mon, Feb 27, 2012 at 11:18 PM, Jacob <[email protected]> wrote:

> I made this fiddle to illustrate my question:
> http://jsfiddle.net/D4qNB/1/
>
> Shouldn't both collections be cloned and adopted into their respective
> parents?
> Am I missing something totally obvious?
>
> Thanks
> Jacob

Reply via email to