On Dec 29, 4:33 am, Jon Kleiser <[email protected]> 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-1.6.0.3.js. var x=[]; x.foo=1; var y=Object.clone(x); alert(y.foo); 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); alert(y.foo); > > /Jon -- kangax --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
