禁用JSHint警告:期望分配或函数调用,而是查看表达式 [英] Disable JSHint warning: Expected an assignment or function call and instead saw an expression

查看:119
本文介绍了禁用JSHint警告:期望分配或函数调用,而是查看表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一行:

imageUrl && (data.imageUrl = imageUrl);

对于这一行,JSHint抱怨:

For this line, JSHint complains:

 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?

推荐答案

如果真的只是一行

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;

这篇关于禁用JSHint警告:期望分配或函数调用,而是查看表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆