Also, is it currently specified if rest parameters can have default
values?  Here's how that might work...

let restDefaults = [2, 3];
let f = function(first, ...rest = restDefaults){}
f(1) // first -> 1, rest -> [2]
f(1, 2) // first -> 1, variableLength -> [], last -> 2

And here's how it might work with an early spread operator...

let g = function(first, ...mid = [2], last = 3){}
g(1) // first -> 1, mid -> [2], last -> 3
g(1, 2) // first -> 1, mid -> [], last -> 2
g(1, 2, 3) // first -> 1, mid -> [2], last -> 3

Also, why not allow default values for lvalues in array destructuring
patterns for symmetry with parameter lists...

// basic case
[x , y = "y", z = "z"] = arr;

// if rest parameter default values are allowed
[x , y = "y", ...z = ["z1", "z2"]] = arr;

// if early spread operator also allowed
[x , ...y = ["y1", "y2"], z = "z"] = arr;


Issues:

Throw if default value is not array-like ?
others ?

Thanks,
Sean Eagan
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to