简体   繁体   English

JSHint重新定义警告并向对象添加更多属性

[英]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: 但JSHint警告我:

[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 eg 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? 或者它被认为是不好的做法?

use this: 用这个:

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

What you are trying is assigning the local variable app to the global variable app . 您正在尝试将局部变量应用程序分配给全局变量应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM