JavaScript Lint inc_dec_within_stmt警告 [英] JavaScript Lint inc_dec_within_stmt warning

查看:85
本文介绍了JavaScript Lint inc_dec_within_stmt警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释为什么javascriptlint(不是jslint)给出警告的原因/重要性

Can someone explain the reason/importance of why javascriptlint (not jslint) gives the warning

inc_dec_within_stmt - increment (++) and decrement (--) operators used as part of greater statement

当遇到一行代码如

someValue = count++;

我为什么要打开此支票?

Why should I keep this check turned on?

推荐答案

这是一个警告,因为这样的陈述对人类读者来说可能是模棱两可的。

It's a warning because a statement like that can be ambiguous to human readers.

你和我可以看一下并且理解它相当于

While you and I can look at that and understand that it is equivalent to

someValue = count;
count = count + 1;

经验不足的程序员可能错误地将其解释为

a less experienced programmer might incorrectly interpret that as

someValue = count + 1;

当然,这是最简单的例子。警告更像是

Of course, this is the simplest example. The warning is much more deserved in a line like

someValue = (count++) * (--index) / (3 * ++j);

虽然我不能说我在生产代码中见过这样的一行:)

although I can't say I've ever seen a line like that in production code :)

这篇关于JavaScript Lint inc_dec_within_stmt警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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