block scoped var

Topics: Language Specification
Nov 14, 2012 at 4:08 PM

function foo(n:int) {
  var result = {};
  for(var index=0; index<n; index++) {{
    var j = index * index;
    result[index] = j;
  }}
  return result;
}
// TS --> JS
function foo(n) {
  var result = {};
  for(var index=0; index<n; index++) {(function(){
    var j = index * index;
    result[index] = j;
  })();}
  return result;
}

If TypeScript could provide block scoped var syntactic sugar, I'd weep tears of joy.

Coordinator
Nov 15, 2012 at 7:33 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.