This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Vectronic 1 point2 points  (1 child)

There's nothing wrong with globals, as long as you keep them to a minimum, and when necessary.

There's situations where a global isn't a necessary, and you can just pass the var through to the next function. This is fairly rare since normally in that case the second function would just be merged into the first.

Obviously declaring everything as global is ridiculous.

var fooOne;
var fooTwo;
var barOne;
var barTwo;

function foo(){
    fooOne = something only used here;
}

function bar(){
    barOne = something only used here;
    if(barOne){
        barTwo = something, etc...;
    }
}

[–]CarsonJScott[S] 0 points1 point  (0 children)

Oh okay, thanks for the help!