De-structuring array arguments

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

De-structuring array arguments

Sultan
Consider the following is not possible today:

function foo ([a, b] = [1, 2]) {}

foo([2, 3])

While the the following is outside of function arguments:

const arr = [1, 2]
const [a, b] = arr

Is there any reason for the current status quo?


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: De-structuring array arguments

Jordan Harband
I'm not sure what you mean, that should certainly be possible today. In node, I get this:
```

function foo ([a, b] = [1, 2]) { return [a, b]; }

foo([2, 3]) // [2, 3]

foo() // [1, 2]

```


On Thu, Jan 17, 2019 at 9:50 AM Sultan <[hidden email]> wrote:
Consider the following is not possible today:

function foo ([a, b] = [1, 2]) {}

foo([2, 3])

While the the following is outside of function arguments:

const arr = [1, 2]
const [a, b] = arr

Is there any reason for the current status quo?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: De-structuring array arguments

Tab Atkins Jr.
On Thu, Jan 17, 2019 at 1:36 PM Jordan Harband <[hidden email]> wrote:
> I'm not sure what you mean, that should certainly be possible today. In node, I get this:
>
> ```
> function foo ([a, b] = [1, 2]) { return [a, b]; }
> foo([2, 3]) // [2, 3]
> foo() // [1, 2]
> ```

Yup, and you get the same in browsers. It definitely works today.

~TJ
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss