本文介绍了JSLint在语句位置的'意外表达'是什么意思。'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中有一个for循环,我已经通过JSLint运行了几次。在过去我收到意外的++错误,我决定重构以使我的代码更具可读性。大约一个月后,JSLint发布了更新,现在显示警告...

I have a for loop in JavaScript that I have run through JSLint a few times. In the past I received the unexpected++ error, I decided to refactor to make my code more readable. A month or so later JSLint came out with an update and is now showing the warning...



//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只是停止处理。

Reverting to var i = 0 and i++ does not get improve the warnings, JSLint just stops processing.

推荐答案

看起来像不是[只是?],因为JSLint处于测试阶段。 这是因为默认情况下Crockford不再允许用于语句。看起来我需要预留一个周末来和。在圈子K,男人正在发生奇怪的事情。

Looks like the follow-up problem isn't [just?] due to JSLint being in beta. It's because Crockford no longer allows for statements by default. Looks like I'm going to need to set aside a weekend to read the new instructions and source. Strange things are afoot at the Circle K, man.

然后在 / * jslint * / 指令部分的主表中:

Then this in the /*jslint */ directive section's main table:

表格下面还有一些解释:

There's a little more explanation below the table:

所以要在新的JSLint中创建这个lint,你需要至少这个代码(用于指令集):

So to make this lint in the new JSLint, you need at least this code (with the for directive set):

/*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 的初始化,因此您可能仍然遇到一个值。我也会承认;我不确定为什么 i + = 1 更好。但现在它看起来像一个艰难的要求。否 plusplus 选项。

Note that I did still have to move i's initialization, so you might still have an issue worth reporting. I'll also admit I'm with Stephen at the question you link; I'm not sure why i+= 1 is better. But now it looks like a hard requirement. No plusplus option.

另请注意,如果代码未包含在函数中(我包含在 test ,上面),你会得到顶级意外'for'。,这是一个新错误。

Notice also that if the code isn't wrapped in a function (I wrapped in test, above), you'll get Unexpected 'for' at top level., which is a new error.

这篇关于JSLint在语句位置的'意外表达'是什么意思。'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 00:58
查看更多