Javascript 禁用 JSHint 警告:需要赋值或函数调用,而是看到了一个表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27623822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable JSHint warning: Expected an assignment or function call and instead saw an expression
提问by Naor
I have the following line:
我有以下几行:
imageUrl && (data.imageUrl = imageUrl);
For this line, JSHint complains:
对于这一行,JSHint 抱怨:
Expected an assignment or function call and instead saw an expression.
I understand the warning, but I want to disable it. I can't find the way how to do it. Any idea?
我理解警告,但我想禁用它。我找不到如何去做的方法。任何的想法?
回答by The Archetypal Paul
If it really is just that one line
如果真的只有那一行
imageUrl && (data.imageUrl = imageUrl); // jshint ignore:line
I am a fan of writing code so it doesn't produce warnings, though, even if this means taking special action to do so. So I'd prefer
我是编写代码的粉丝,因此它不会产生警告,即使这意味着要采取特殊措施来这样做。所以我更愿意
if (imageUrl) data.imageUrl = imageUrl;
回答by Paul Roub
Include a /* jshint expr: true */comment in your Javascript.
/* jshint expr: true */在您的 Javascript 中包含注释。
Reference: http://jshint.com/docs/options/#expr

