Comments on Refutable Patterns proposal

Brandon Benvie bbenvie at mozilla.com
Thu Mar 21 11:16:07 PDT 2013


On 3/21/2013 10:54 AM, Tab Atkins Jr. wrote:
> On Thu, Mar 21, 2013 at 10:51 AM, Brandon Benvie <bbenvie at mozilla.com> wrote:
>> On 3/21/2013 10:14 AM, Axel Rauschmayer wrote:
>>>> And with rest patterns at the end only, I don't think you'd ever want
>>>> to write "..." without a subpattern. The only difference between [x,
>>>> y] and [x, y, ...] would be that the latter (somewhat redundantly)
>>>> checks the presence of a length property.
>>> Ah! I would expect [x,y] to only match arrays whose length is 2. Is there a
>>> benefit to being more lenient?
>> I wouldn't expect that at all, for the same reason I would expect `let { x,
>> y } = { x: 1, y: 2, z: 3 }` to work.
> And in Python, for example, I often get annoyed when the interpreter
> reminds me that the length of an unpacked tuple must be the same as
> the originating tuple, even if I'm intentionally ignoring the end of
> it.
>
> ~TJ
This also. I think a common use case is to grab the items at the 
beginning of a variable (or even unknown) length array. I also don't see 
the benefit of requiring exact length matching, especially when it would 
require adding additional syntax to bring back the ability to work with 
variable/unknown length arrays.


More information about the es-discuss mailing list