XML Feeds

.

[javascript-dev] Re: Re: [sharingisfun] js based change filter

Emmanuel Jourdan c74-mailinglists at e--j.com
Sat Sep 8 08:32:14 MDT 2007


On 8 sept. 07, at 05:06, John Pitcairn wrote:

> I don't see any practical difference between a hypothetical array  
> copy method like:
>
> newarray = oldarray.copy();
>
> and using the slice method:
>
> newarray = oldarray.slice(0);
>
> But in any case, you can always add a copy method to the Array  
> object prototype:
>
> Array.prototype.copy = function()
> {
> return this.slice(0);
> }
>
> a = new Array(1, 2, 3, 4, 5);
> b = a.copy();
> post(b);

There's no difference, except that it's built-in, so you don't even  
have to modify the array prototype. I always found it weird to have  
to use slice(0) to make a copy of an array…

ej





More information about the javascript-dev mailing list