Array extras feedback

Jeff Walden jwalden+es at MIT.EDU
Thu Jul 30 16:55:53 PDT 2009

Brendan asked me yesterday to look at and comment on the array extras methods as they exist in ES5, since things are being finalized yesterday and today.  (I'm not sure whether yesterday was the latest to make these comments or whether today is also acceptable; unfortunately Black Hat proceedings destroyed my day yesterday.  So it goes.)  Overall they look fine; I find myself somewhat amused that the descriptions in the spec are apparently copied from MDC with slight modifications, improvements, and clarifications.  :-)

The biggest change, using SameValue rather than ===, is certainly a good change; we should have noticed that when creating the method in the first place.

The only real issue I noticed -- a small issue, not especially critical but worth noting in passing, was this: indexOf and lastIndexOf return early if this array-like object has length zero.  In particular they return before this step (the only side-effectful step that's short-circuited):

   If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be len.

Thus, when indexOf and lastIndexOf are used, the provided fromIndex is converted to an integer -- except when this array is empty.  Why should this behavior differ when the array has one element and when it has zero?  I believe it would be more consistent for fromIndex to always be converted to integer (assuming the callback is properly callable and that the indexOf call otherwise conforms to expected use), even if this array is empty.

Anyway, if this doesn't make it in time to be considered, so be it.  If it does, I'm not arguing particularly vociferously in favor of it, but it seems like an unnecessary difference from what we've already implemented, and I don't see an obvious motivation for it.


More information about the es-discuss mailing list