holes in spread elements/arguments
Sean Eagan
seaneagan1 at gmail.com
Thu Sep 29 11:07:01 PDT 2011
Sorry to drag on about array holes, but:
Should holes in spread elements (e.g. [...holeyArray]) and arguments
(e.g. f(...holeyArray)) reflect as holes in the array they are spliced
into to avoid information loss ? The current proposal [1] reflects
them as `undefined` values.
Spread arguments will reflect in both the `arguments` array and the
rest parameter binding if there is one, so this would allow them to
have holes. The only issue I see is that Function.prototype.apply
reflects holes as `undefined` values in the `arguments` array, so if
`f` is a function whose code loops over `arguments` skipping holes
(most likely via ES5 Array extras), then the following migration could
cause holes to be skipped which were previously not:
f.apply(holeyArray)
->
f(...holeyArray)
This should be rare, since for one thing holey arrays are rare, and
it's unlikely anything important was being done with the `undefined`
values which are now being skipped. If this is an issue, the holes
could only be reflected in rest parameter bindings since they are
meant to replace `arguments` in the long run anyways.
On a separate note, I'm not sure if argument lists should be made
symmetric to array element lists, by allowing them to have holes (e.g.
f(1, , 3)), but it would essentially allow `undefined` arguments to be
ommitted, if that would be considered useful.
[1] http://wiki.ecmascript.org/doku.php?id=harmony:spread
Thanks,
Sean Eagan
More information about the es-discuss
mailing list