samedi 9 mai 2015

Is this considered as a bad practice for regarding to scopes and variables? [duplicate]

This question already has an answer here:

Let's say I have the following code:

var app = {};

app.post = {
    foo: function() {
        // defining a variable without the 'var' keyword inside a function.
        bar = "Hello!";
    }
}

I think the way that I defined the bar variable is not good. I know you shouldn't have global variables. but, I defined it inside of a method which is inside of an object.

Is it a bad practice?

Aucun commentaire:

Enregistrer un commentaire