Destructuring by &reference

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Mar 3 17:44:27 UTC 2021


> the proposal is just a debatable syntax sugar for something we already
can do

that's basically the entirety of the syntax sugar proposals since ES2015,
right? also proxy and globalThis are *really* unrelated to this, imho,
while leaking objects all over down the pipe is my major concern, something
this proposal avoids, as no code will have a reference to the entirety of
the source object, they'll deal with a known property name passed by
reference, incapable of changing anything else in the source object ... so
it's rather a signal, than a convention.

this means composability, different classes/prototypes passed as arguments,
and the certainty nothing can inspect, change, or deal, with the source,
which means increased security, as opposite to pass instances and whole
objects references around.

You have a reference to a property, you don't see its source.


On Wed, Mar 3, 2021 at 6:19 PM Augusto Moura <augusto.borgesm at gmail.com>
wrote:

> > ```js
> > function stuff(source, extra) {
> >   const {value, method} = source;
> >
> >   if (condition)
> >     method.call(source);
> >
> >   if (value === extra)
> >     source.value = 'no more';
> > }
> > ```
>
> I mean, in this case you can skip destructuring altogether, having a one
> way and way only of value indirection is a Pretty Good Thing™ (even though
> we already have proxys, globalThis and other indirection shenanigans), I
> never felt annoyed of just using `source.value` or `source.method()`
> instead of `value` and `method()`, again the proposal is just a debatable
> syntax sugar for something we already can do. I wonder if we could ever do
> the reference thingy in user-land with variable level decorators, if it
> ever gets discussed again in the meetings. Would be still kinda fishy to
> propose and implement
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20210303/bb0d1136/attachment.html>


More information about the es-discuss mailing list