最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论