Proposal: Named de-structuring arguments.

Sultan thysultan at
Wed Jan 16 08:23:41 UTC 2019

The ability to both name and de-structure an argument.

Relying on the spread operator does not archive the same effect considering
that the spread operator "by design" has some short-comings related to
exotic objects when the objects in question have a rich prototype you want
to preserve.

Consider the following proposal:

function fn (arg pick {a, b = arg.b = 'value'}) {}

This would allow four fundamental things of note missing from current
de-structuring status-quo:

1. The ability to have both named arguments and de-structuring.

2. The ability to reference the named argument within the de-structure.
This allows the above pattern of setting a default value on the passed
argument when it doesn't exist.

3. This in turn also affords you the ability to de-structure while also
preserving the exotic nature of an object when it is not a POJO object.

That is when "arg" is an exotic use-defined object using the spread
operator "{...arg}" will discard its prototype.

For example:

function a ({a, ...b}) { return b }

a([1, 2])

Returns a object with index-able keys instead of the array.

4. Consequently this addition would also afford the avoidance of any
overhead that one might want to avoid with the rest spread operation: {a,
b, ...arg} in hot paths.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list