Spread and non objects

Jon Zeppieri jaz at bu.edu
Fri Nov 5 10:30:25 PDT 2010

On Fri, Nov 5, 2010 at 11:16 AM, Mike Samuel <mikesamuel at gmail.com> wrote:

> 2010/11/5 Jon Zeppieri <jaz at bu.edu>:
> >
> > To the extent that the spread operator and rest args should be
> symmetrical,
> > the following function should be an identity over its domain:
> > function id(x) {
> >   return (function(...x) { return x; })(...x);
> > }
> > But it can only be an identity when its argument is an array.
> What do you think should happen with id(arguments)?
> I tend to think it's best to launder arguments where possible to stop
> the spread of unintended authority early.

No argument here. My claim about id only being an identity when its argument
is an array assumes that the rest arg mechanism works as proposed -- i.e.,
that the rest parameter is always bound to an array, not to an array-like or
anything else. So, if symmetry were valuable, then id(arguments) would

But... I hadn't realized that the spread proposal already included
array-likes. In that case, there is no symmetry to preserve. The (now badly
misnamed) id function will produce an array from an array-like -- and from
null or undefined, under plan B. I think that second part feels a bit
hack-y, and as Brendan pointed out, spread isn't simply sugar for apply.
Plan B is meant to eliminate an inconvenient null check, but I'm a bit
concerned that the proposed behavior will simply hide actual bugs, as
automatic coercions often do. That said, automatic coercions are commonplace
in ES already.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20101105/76d7c76d/attachment.html>

More information about the es-discuss mailing list