Wanted: standard Array function to append an array's elements to another array

David Flanagan dflanagan at mozilla.com
Wed Jul 27 09:21:11 PDT 2011


On 7/25/11 12:54 PM, Jeff Walden wrote:
>   Object.defineProperty(Array.prototype, "pushAll",
>   {
>     enumerable: false, configurable: true, writable: true,
>     value: function pushAll(other)
>     {
>       "use strict";
>       var t = ToObject(this);
>       var length = ToUint32(t.length);
>       var otherLen = other.length;
>       for (var i = 0, j = length; i < otherLen; i++, j++)
>         t[j] = other[i];
>       t.length = j;
>       return void 0;
>     },
>   });
>
> Comments?  Suggestions?  Requests for changes? 
Could you return this instead of undefined so that we can chain calls? 
For example:

    a.pushAll(b).pushAll(c).sort()


More information about the es-discuss mailing list