JavaScript Lint inc_dec_within_stmt 警告

发布于 2024-07-26 15:21:46 字数 274 浏览 0 评论 0原文

发出警告的原因/重要性?

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

这样的代码行时

someValue = count++;

有人可以解释为什么 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

when it comes across a line of code like

someValue = count++;

Why should I keep this check turned on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撧情箌佬 2024-08-02 15:21:46

这是一个警告,因为这样的声明对于人类读者来说可能会产生歧义。

虽然你和我可以看到它并理解它相当于

someValue = count;
count = count + 1;

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

someValue = count + 1;

当然,这是最简单的例子。 在这样的行中更值得发出警告:)

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

尽管我不能说我在生产代码中见过这样的行,但

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文