Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSHint redefinition warning and adding more properties to object

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?

like image 316
Michal Ostruszka Avatar asked Sep 19 '13 10:09

Michal Ostruszka


1 Answers

use this:

window.app = window.app || {};

What you are trying is assigning the local variable app to the global variable app.

like image 83
Rusi Papazov Avatar answered Sep 28 '22 06:09

Rusi Papazov