.. cascade operator

Hugh Jackson hughfdjackson at googlemail.com
Sat Jul 21 17:05:18 PDT 2012


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>


More information about the es-discuss mailing list