Spread and non objects

Erik Arvidsson erik.arvidsson at gmail.com
Fri Nov 5 15:10:16 PDT 2010


Thanks for all the feedback. I've updated
http://wiki.ecmascript.org/doku.php?id=harmony:spread to reflect this.

On Fri, Nov 5, 2010 at 10:30, Jon Zeppieri <jaz at bu.edu> wrote:
>
>
> 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
> throw.
> 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.
>
>



-- 
erik


More information about the es-discuss mailing list