On Dec 29, 4:33 am, Jon Kleiser <jon.klei...@usit.uio.no> wrote:
> Hi,
> The Prototype docs on Object.clone() says that it
> "Clones the passed object using shallow copy (copies all the
> original's properties to the result)."

It's good to remember that `Object.clone` "copies" all *enumerable*
properties of an object or its prototype chain.

> However, if I give my array some extra properties, they will not get copied!
> Try this:
> var x=[];x.foo=1;var y=x.clone();alert(y.foo);

You're using `Array.prototype.clone` here, not `Object.clone`.
`Array.prototype.clone` only "affects" numeric properties (since
internally it uses `Array.prototype.concat` in older versions and
`Array.prototype.slice` in trunk version)

> Rather disappointing!
> I'm using prototype-

var x=[];
var y=Object.clone(x);

Although, this will make `y` an object (not an array). To "fix" this,
you can do something like:

var x = [1,2,3];
x.foo = 1;
var y = x.clone();
Object.extend(y, x);

> /Jon

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to