javascript - JSHint redefinition warning and adding more properties to object - Stack Overflow

I have object definition spanning multiple files and I use the following syntax to add more properties

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 badges
Add a ment  | 

1 Answer 1

Reset to default 11

use this:

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743957758a4536099.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信