On Sun, Sep 28, 2014 at 8:49 AM, Stephan Beal <[email protected]> wrote:
> In JS there are only 2 scopes: global and local function scope, so that > (var e) behaves as if it's declared outside of the for loop, whether or not > it really is. Kinda silly, i know. > Had to go clarify that for my own sake: http://dailyjs.com/2012/07/23/js101-scope/ See the section entitled "no block scope". Alternately, if the email client doesn't mangle it, here it is pasted in: -------------------- No Block Scope Variables and functions are visible within the current function, regardless of blocks. This is amazingly confusing because it prevents us from using control structures to declare functions and variables in a dynamic way. Defining variables in blocks may confuse programmers who work with other languages: function example() { // Do not do this for (var i = 0; i < 3; i++) { var a = 1; // Do stuff with `a` }} Since there is no block scope, the previous example should be written like this: function example() { var i, a; for (i = 0; i < 3; i++) { a = 1; // Do stuff with `a` }} -------------------- That said: JS behaves the same either way, so it's a question of style, not of correctness. i.e. don't bother going back and changing it unless this detail keeps you up at night ;). -- ----- stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________ fossil-users mailing list [email protected] http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

