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

Jeff Walden jwalden+es at MIT.EDU
Fri Jul 29 15:10:23 PDT 2011

On 07/29/2011 05:22 AM, Andrea Giammarchi wrote:
> to avoid apply limits is actually trivial

More or less, yes.

But it requires the developer to anticipate the concern in advance that the elements being appended might consume all available stack space.  I don't think most developers think at all about the size of the stack, or about its being limited, except when they write a recursive algorithm, intentionally or inadvertently, and neglect to correctly implement the base case.  I certainly forgot about this concern when I wrote the buggy code which initially triggered this request, and I think it's reasonably apparent there's a problem when even a JS engine implementer makes this mistake.

Past that, your MAX_LENGTH constant would have to be lower than the max length across all JS engines cared about.  I find it concerning that something as simple as extending an array with the elements of another array would require an implementation-dependent workaround, when this operation is built-in functionality in other mainstream languages where mutation is common:

C++: vector<T>::insert

C#: List<T>.AddRange

Java: List<E>.addAll

Perl: push

Python: list.extend

Ruby: array.concat


More information about the es-discuss mailing list