.. cascade operator
# Hugh Jackson (12 years ago)
Apologies for the formatting; i promise it looked far more reasonable in gmail ;)
Apologies for the formatting; i promise it looked far more reasonable in gmail ;) On 22 July 2012 01:03, Hugh Jackson <hughfdjackson at googlemail.com> wrote: > Many js APIs rely heavily on chaining, which is somewhat limited, in that > the object upon which further methods are to be called has to be returned; > as well as providing setter methods. Is there space in JS for this > proposal (taken from dart<http://www.dartlang.org/articles/m1-language-changes/#cascades> > )?: > > query('#my-form').query('button') > > ..classes.add('toggle') > > ..text = 'Click Me!' > > ..labels.add(toggleLabel); > > > Which desugars to: > > query('#my-form').query('button').classes.add('toggle'); > > query('#my-form').query('button').text = 'Click Me!'; > > query('#my-form').query('button'.labels.add(toggleLabel); > > > IOW, .. evaluates the expression that follows it, and returns the value of > the previous expression (discarding the value returned from the expression > being evaluated). > > I understand that .{ has been considered in this context, but (afaic) it > doesn't seem to cover as many bases as minimally. > > Hugh > > -- Hugh Jackson: Web Development Mobile: 0797 609 1579 Email: hughfdjackson at googlemail.com Code: github.com/hughfdjackson Twitter: @hughfdjackson -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120722/cef8826b/attachment-0001.html>
# Brendan Eich (12 years ago)
See blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache -- I'm not sure there is a strawman on the wiki, though.
See http://blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache/ -- I'm not sure there is a strawman on the wiki, though. /be Hugh Jackson wrote: > Many js APIs rely heavily on chaining, which is somewhat limited, in > that the object upon which further methods are to be called has to be > returned; as well as providing setter methods. Is there space in JS > for this proposal (taken from dart > <http://www.dartlang.org/articles/m1-language-changes/#cascades>)?: > > query('#my-form').query('button') > > ..classes.add('toggle') > > ..text = 'Click Me!' > > ..labels.add(toggleLabel); > > > Which desugars to: > > query('#my-form').query('button').classes.add('toggle'); > > query('#my-form').query('button').text = 'Click Me!'; > > query('#my-form').query('button'.labels.add(toggleLabel); > > > IOW, .. evaluates the expression that follows it, and returns the > value of the previous expression (discarding the value returned from > the expression being evaluated). > > I understand that .{ has been considered in this context, but (afaic) > it doesn't seem to cover as many bases as minimally. > > Hugh > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss
# Hugh Jackson (12 years ago)
Very interesting;
Very interesting; thanks! On 22 July 2012 01:32, Brendan Eich <brendan at mozilla.org> wrote: > See http://blog.mozilla.org/**dherman/2011/12/01/now-thats-** > a-nice-stache/<http://blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache/>-- I'm not sure there is a strawman on the wiki, though. > > /be > > Hugh Jackson wrote: > >> Many js APIs rely heavily on chaining, which is somewhat limited, in that >> the object upon which further methods are to be called has to be returned; >> as well as providing setter methods. Is there space in JS for this >> proposal (taken from dart <http://www.dartlang.org/** >> articles/m1-language-changes/#**cascades<http://www.dartlang.org/articles/m1-language-changes/#cascades> >> >)?: >> >> >> query('#my-form').query('**button') >> ..classes.add('toggle') >> >> ..text = 'Click Me!' >> ..labels.add(toggleLabel); >> >> >> Which desugars to: >> >> query('#my-form').query('**button').classes.add('toggle')**; >> query('#my-form').query('**button').text = 'Click Me!'; >> >> query('#my-form').query('**button'.labels.add(**toggleLabel); >> >> >> IOW, .. evaluates the expression that follows it, and returns the value >> of the previous expression (discarding the value returned from the >> expression being evaluated). >> >> I understand that .{ has been considered in this context, but (afaic) it >> doesn't seem to cover as many bases as minimally. >> >> Hugh >> ______________________________**_________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120722/af4ddb62/attachment.html>
# Man Hoang (6 years ago)
This operator should have been added years ago. It would enable many APIs to return more appropriate results instead of this
.
For example, Set.prototype.add(value)
could return a boolean indicating if an item was actually added instead of this
.
This operator should have been added years ago. It would enable many APIs to return more appropriate results instead of `this`. For example, `Set.prototype.add(value)` could return a boolean indicating if an item was actually added instead of `this`. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181010/a6e2e98f/attachment.html>
# Luan Nico (6 years ago)
I agree with this, Dart has the exact thing and it's amazing. Not sure what's the status or reason for not following through, though.
I agree with this, Dart has the exact thing and it's amazing. Not sure what's the status or reason for not following through, though. On Wed, Oct 10, 2018 at 3:54 AM Man Hoang <jolleekin at outlook.com> wrote: > This operator should have been added years ago. It would enable many APIs > to return more appropriate results instead of `this`. > > > > For example, `Set.prototype.add(value)` could return a boolean indicating > if an item was actually added instead of `this`. > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181010/f8b36c31/attachment.html>
Many js APIs rely heavily on chaining, which is somewhat limited, in that the object upon which further methods are to be called has to be returned; as well as providing setter methods. Is there space in JS for this proposal (taken from dartwww.dartlang.org/articles/m1-language-changes/#cascades )?:
query('#my-form').query('button')
..classes.add('toggle')
..text = 'Click Me!'
..labels.add(toggleLabel);
Which desugars to:
query('#my-form').query('button').classes.add('toggle');
query('#my-form').query('button').text = 'Click Me!';
query('#my-form').query('button'.labels.add(toggleLabel);
IOW, .. evaluates the expression that follows it, and returns the value of the previous expression (discarding the value returned from the expression being evaluated).
I understand that .{ has been considered in this context, but (afaic) it doesn't seem to cover as many bases as minimally.
Hugh