Cascade in the language

Herby Vojčík herby at mailbox.sk
Fri Dec 7 00:55:40 PST 2012


Hello
it seems to me that with new language construct jn ES6, there sort-of is 
a spartan support for cascading.

Instead of

    a[i].set.add("bar");
    a[i].set.forEach(...);

one can do

   { let s = a[i].set;
     s.add("bar");
     s.forEach(...);
   }

or

   (s = a[i].set) => {
     s.add("bar");
     s.forEach(,,,);
   }();

But msybe there can be more direct support for cascading there...

   a[i].set.{
     add("bar");
     forEach(...);
   };

was rejected. But there may be simpler possibilities, which are less 
generic then the previous.

For example, one can try to exploit parentheses' role in the language 
(as opposed to the math) of "btw-omittable-insertion" and do something like

   a[i].set
     (.add("bar"))
     (.add("baz"))
     .forEach(...);

optionally contractible to

   a[i].set
     (.add("bar"), .add("baz"))
     .forEach(...);

This is simpler than .{...} from above by strictly allowing only method 
calls; no ".foo" or ".foo = 4".
I know, ASI and parser disambiguating may strike back here.
But anyway.

Herby

P.S.:

Less disambiguation-unfriendly variant is

   a[i].set
     .(add("bar"), add("baz"))
     .forEach(...);


More information about the es-discuss mailing list