我在 JavaScript 中有一个 for 循环,我已经通过 JSLint 运行了几次。过去我收到 the unexpected++ error
,我决定重构以使我的代码更具可读性。大约一个月后,JSLint 发布了更新,现在显示警告......
//See JSLint.com for why I pulled out i initialization and i = i+1 instead of i++
//and http://stackoverflow.com/questions/3000276/the-unexpected-error-in-jslint
var i = 0;
for (i; i < scope.formData.tabs.length; i += 1) {
scope.formData.tabs[i].show = false; // hide all the other tabs
if (scope.formData.tabs[i].title === title) {
scope.formData.tabs[i].show = true; // show the new tab
}
}
恢复到
var i = 0
和 i++
不会改善警告,JSLint 只是停止处理。 最佳答案
看起来 the follow-up problem 不是 [只是?] 由于 JSLint 处于测试阶段。 这是因为 Crockford 默认不再允许 for
语句。 看起来我需要留出一个周末去 read the new instructions 和 source 。伙计,Circle K 正在发生奇怪的事情。
然后在 /*jslint */
指令部分的主表中:
表格下方还有一点说明:
因此,要在新的 JSLint 中制作此 lint,您至少需要以下代码(使用 for
指令集):
/*jslint white:true, for:true */
/*global scope, title */
function test()
{
"use strict";
var i;
for (i=0; i < scope.formData.tabs.length; i = i + 1) {
scope.formData.tabs[i].show = false; // hide all the other tabs
if (scope.formData.tabs[i].title === title) {
scope.formData.tabs[i].show = true; // show the new tab
}
}
}
请注意,我仍然需要移动
i
的初始化,所以你可能仍然有一个值得 reporting 的问题。我也承认 I'm with Stephen at the question you link ;我不确定为什么 i+= 1
更好。但现在它看起来像是一个硬性要求。没有 plusplus
选项。另请注意,如果代码未包装在函数中(我包装在
test
中,上面),您将得到 Unexpected 'for' at top level.
,这是一个新错误。关于javascript - JSLint 的 'Unexpected expression ' i' 在语句位置是什么意思。'?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30265001/