block closure simplifications

Topics: Language Specification
Jan 29, 2013 at 9:46 AM
Edited Jan 29, 2013 at 9:47 AM

Hello,

the current notation for block closure in typescript is quite widespread today among the different languages.. It could be interesting for some cases to simplify it...

1) no argument block

we could have 
    {: something to do }
instead of
    ()=> { something to do }

2) enabling supressing parenthesis for only one argument, or when arguments with no typing information

we could have 
  x:string  => {: something to do }
  x,y =>  {something to do }
instead of
  (x:sting)=> { something to do }
  (x,y) = { something to do }

3) enabling the following alternative notation (inspired from smalltalk or objectiveC)

   { x:string =>
       .... var y = x; }

instead of

  (x:string) => {
       ... var y = x; }

4) use the groovy convention when a block is the last argument of the function

instead of :
var xxx= dummy(var1, var2,  ()=>{ .... });
var xxx= dummy(var1, var2, (x,y)=>{ .... });

being able to write :
var xxx = dummy(var1,var2) {...};
var xxx= dummy(var1, var2) { x,y => .... });

best regards

Xavier

Coordinator
Jan 29, 2013 at 5:05 PM

There is a block scope proposal in the ECMAScript 6 proposal that uses the 'let' keyword, which would let you bind a variable and control it's scope how (I think) you're suggesting.  We'll likely adopt this feature once its been ratified.

Here's a good page for information on block scope in ES6.