New ES6 strawman: Array.prototype.fill and Array.prototype.move

Brendan Eich brendan at mozilla.com
Sun Jun 23 18:41:45 PDT 2013


Thanks, I added to the Answer:


  Discussion

Q: Does anyone know of a rationale for why (start, end) might be a 
better design pattern than (start, count) for such operation?

A: Array.prototype.slice uses (start, end) where end is a fencepost to 
facilitate looping over half-open ranges within a larger range. Spec’ing 
count requires subtracting next_start - end, gratuitously. Also, 
consistency with slice and range APIs matters. This should be considered 
carefully in the design.

Furthermore, as Tab Atkins reminds on es-discuss, (start, end) supports 
negative indexes for both arguments (measured from length).

— /Brendan Eich 
<mailto:%26%23x62%3B%26%23x72%3B%26%23x65%3B%26%23x6e%3B%26%23x64%3B%26%23x61%3B%26%23x6e%3B%26%23x40%3B%26%23x6d%3B%26%23x6f%3B%26%23x7a%3B%26%23x69%3B%26%23x6c%3B%26%23x6c%3B%26%23x61%3B%26%23x2e%3B%26%23x6f%3B%26%23x72%3B%26%23x67%3B> 
2013/06/24 01:38/


/be

Tab Atkins Jr. wrote:
> On Sun, Jun 23, 2013 at 1:36 PM, Brendan Eich<brendan at mozilla.com>  wrote:
>> Q: Does anyone know of a rationale for why (start, end) might be a better
>> design pattern than (start, count) for such operation?
>>
>> A: Array.prototype.slice uses (start, end) where end is a fencepost to
>> facilitate looping over half-open ranges within a larger range. Spec’ing
>> count requires subtracting next_start - end, gratuitously. Also, consistency
>> with slice and range APIs matters. This should be considered carefully in
>> the design.
>
> In sane designs, start/end is better because you can specify negative
> indexes for either argument.  Very useful.  There is no analog of this
> for start/count.
>
> Also, I use .slice() a lot, and consistency with that would be great.
> Inconsistency between start/end and start/count is one of the (many)
> reasons I hate PHP.
>
> ~TJ
>


More information about the es-discuss mailing list