I have object definition spanning multiple files and I use the following syntax to add more properties to namespace
var app = app || {};
// and then
app.namespace = {
...
}
But JSHint warns me with stuff like:
[L1:C5] W079: Redefinition of 'app'.
var app = app || {};
I'm not sure if this is really wrong as I've seen it used many times e.g. together with module pattern.
If that's ok, how can I globally supress that warning? I've found a way to supress given option for given file with
/* jshint: -W079 */
but is there a way to do it globally? Or is it considered bad practice?
I have object definition spanning multiple files and I use the following syntax to add more properties to namespace
var app = app || {};
// and then
app.namespace = {
...
}
But JSHint warns me with stuff like:
[L1:C5] W079: Redefinition of 'app'.
var app = app || {};
I'm not sure if this is really wrong as I've seen it used many times e.g. together with module pattern.
If that's ok, how can I globally supress that warning? I've found a way to supress given option for given file with
/* jshint: -W079 */
but is there a way to do it globally? Or is it considered bad practice?
Share Improve this question asked Sep 19, 2013 at 10:40 Michal OstruszkaMichal Ostruszka 2,0992 gold badges21 silver badges24 bronze badges1 Answer
Reset to default 11use this:
window.app = window.app || {};
What you are trying is assigning the local variable app to the global variable app.