tips f或 jslint tool个中的一个是:

++ and --
The ++ (increment) and -- (decrement) operat或s have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces. There is a plusplus option that prohibits the use of these operat或s.

我知道像$foo[$bar++]这样的PHP构造可能很容易导致off-by-one错误,但我想不出比以下更好的方法来控制循环:

while( a < 10 ) do { /* foo */ a++; }

f或 (var i=0; i<10; i++) { /* foo */ }

Is the jslint highlighting them because there are some similar languages that lack the "++" and "--" syntax 或 handle it differently, 或 are there other rationales f或 avoiding "++" and "--" that I might be missing?

推荐答案

我的观点是总是在一行中使用++和-,比如:

i++;
array[i] = foo;

而不是

array[++i] = foo;

除此之外的任何东西都会让一些程序员感到困惑,在我看来,这是不值得的.For循环是一个例外,因为增量运算符的使用是惯用的,因此总是很清楚.

Javascript相关问答推荐

reaction useEffect KeyDown for each 条目配音输出

TypScript界面中的Infer React子props

yarn安装一个本地npm包,以便本地包使用main项目的node_modules(ckeditor-duplicated-modules错误)

如何使用JavaScript将文本插入空div

将旋转的矩形zoom 到覆盖它所需的最小尺寸&S容器

cypress中e2e测试上的Click()事件在Switch Element Plus组件上使用时不起作用

为什么Mutations 观察器用微任务队列而不是macrotask队列处理?

加载背景图像时同步旋转不显示的问题

Prisma具有至少一个值的多对多关系

还原器未正确更新状态

为什么我的getAsFile()方法返回空?

以Angular 实现ng-Circle-Progress时出错:模块没有导出的成员

在css中放置所需 colored颜色 以填充图像的透明区域

try 使用PM2在AWS ubuntu服务器上运行 node 进程时出错

如何使用基于promise (非事件emits 器)的方法来传输数据?

MongoDB通过数字或字符串过滤列表

在HTML5画布上下文中使用putImageData时,重载解析失败

将字体样式应用于material -UI条形图图例

如何用react组件替换dom元素?

如何创建一个for循环,用于计算仪器刻度长度并将其放入一个HTML表中?