vendredi 6 février 2015

Is this pattern to reduce the scope of variables declared within an if statement a good practice?

I saw this pattern recently



if(condition) {
(function() {
var foo = "bar";
// do somehing with foo
})();
}
// no more foo


It looks a little bit like a hack, and I was wondering if the usage of this pattern is a good practice?


Aucun commentaire:

Enregistrer un commentaire