Mutable array methods

David Bruant bruant.d at gmail.com
Thu Mar 8 08:45:16 PST 2012


Le 08/03/2012 13:02, Maël Nison a écrit :
> Hi,
>
> I'm just wondering why there is no mutable function with Javascript 
> arrays.
>
> For exemple, if I want to remove every entry matching 42 from an 
> array, I will have to write something like :
>
> > var array = [ 0, 1, 42, 3, 4, 5, 42, 42, 42 ];
> > array = array.filter( function ( x ) { return x === 42; } );
>
> Why is it necessary to make a copy ? Why can't we just write something 
> like this ?
>
> > var array = [ 0, 1, 42, 3, 4, 5, 42, 42, 42 ];
> > array.mfilter( function ( x ) { return x === 42; } ); // mutable filter
>
> (...)
>
> Is there a reason for these missing functions ?
None besides history.
It's still possible to add these functions to Array.prototype yourslef, 
though.

David


More information about the es-discuss mailing list