On Thu, Nov 4, 2010 at 10:34 PM, Jon Zeppieri <[email protected]> wrote:

>
>
> On Thu, Nov 4, 2010 at 10:06 PM, Jon Zeppieri <[email protected]> wrote:
>
>>
>>
>> On Thu, Nov 4, 2010 at 9:12 PM, Brendan Eich <[email protected]> wrote:
>>
>>> On Nov 4, 2010, at 6:07 PM, John Lenz wrote:
>>>
>>> It would seem friendlier for the spread operator to treat it them as a
>>> empty array otherwise you end up with code like:
>>>
>>> if (x!=null) {
>>>   f(1,2,...x)
>>> } else  {
>>>   f(1,2)
>>> }
>>>
>>>
>>> Yeah, null testing is a drag. People skipt it (I hear this about regexp
>>> exec -- it should return an empty array on mismatch -- counter-argument is
>>> that empty arrays are truthy).
>>>
>>
>>
>> The dual of spread-as-operator is spread-as-rest-arg-syntax. What happens
>> in the case of:
>>
>> function foo(x, y, ...z) { [...] }
>>
>> foo(1, 2, null);
>>
>> Will z be bound to an empty array or to an array containing a single null?
>> I'd expect the latter, and that answer seems more in-line with Erik's plan
>> A.
>>
>
> Erm, on second thought, I got that completely wrong. The fact that z would
> be [null] doesn't pose any problem for plan B. The rest arg syntax always
> ensures that z is bound to an array, so it makes good sense that the
> operator would always produce one.
>

Oh my.

Take three.

Spread-as-rest-arg-syntax constructs an array. Spread-as-operator splices
the elements of an array into an argument list.

So, if a spread operator expression: ...null splices zero values into an
argument list, then its counterpart would be something like:

function foo(x, y, ...z) { }

foo(1, 2);

... where we pass zero optional arguments to foo, and z is bound to an empty
array. Which is what we'd expect. So, yeah, plan B makes sense.





>
>
>
>>
>> -Jon
>>
>>
>>
>>
>>> +1 on Erik's plan B.
>>>
>>> /be
>>>
>>>
>>>
>>> On Thu, Nov 4, 2010 at 5:54 PM, Erik Arvidsson <[email protected]
>>> > wrote:
>>>
>>>> We've run into an edge case with the spread operator. What should
>>>> happen if we try to spread null or undefined?
>>>>
>>>> f(...undefined);
>>>>
>>>> A. Throw an error
>>>> B. Follow the path of Function.prototype.apply and others and special
>>>> case null and undefined and just call f with 0 arguments
>>>>
>>>> --
>>>> erik
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to