Feature request: blockscope

10 views
Skip to first unread message

Andreas Hoffmann

unread,
Feb 3, 2015, 5:49:11 AM2/3/15
to jsh...@googlegroups.com
Hi,

is there any chance to have an additional option implemented?
Let's have a look at the following code:

function foo(){
  "use strict";
  var a = [];
  for (var i=0;i<10;i++) {  }
  var a = [];
  for (var i = 0; i<10; i++) {  }
}

Two warnings are coming up:
1.) "a is already defined"
2.) "i is already defined"

Is there any chance to get an option that treats var-declarations with "blockscope", like in Java or C#?

IMO, the duplicate declaration of "i" is perfectly fine and even good coding style. Moving the index-variables to the top of methods would just reduce readability without gaining anything.

I know the details about variable declaration in javascript, but that does not mean that I like them :-)

Any chance, this might get implemented?

Regards
Andreas

Jamund Ferguson

unread,
Feb 3, 2015, 10:41:56 AM2/3/15
to jsh...@googlegroups.com
Are you familiar with "let", which is an ES6 (latest javascript version) feature that provides actual block scope?

You can read more about it here:

Might be a better solution than pretending to have to block scope?
Reply all
Reply to author
Forward
0 new messages