【问题标题】:Jslint does not recognize option for misordered functionsJslint 无法识别功能错误的选项
【发布时间】:2012-08-18 19:15:57
【问题描述】:

我使用 JavaScript 注释来设置选项

/*jslint undef: false, browser: true */

根据jslint documentation here 容忍错误排序的函数和变量定义。我也尝试将其设置为“true”,但这也不起作用。

但我还是得到了

'vFlipB' 在定义之前使用。

        vFlipB('mi_cover');

这个函数首先在第 299 行被调用:

Mo.UserAny = {
    pre : function (o_p) {
        vFlipB('mi_cover');
        if ((localStorage.hash === '0') || (localStorage.hash === undefined) || (localStorage.hash === null)) {
            o_p.result = 'complete';
            Vi.Ani.flipP('sp');
            return o_p;
        }

。 . .

但是直到它下面才被定义:

在 958 上

/**
 **  vFlipB
 */

function vFlipB( current_id ) {

    // turn on

    var current_link = document.getElementById( current_id + '_l' ),
        current_box = document.getElementById( current_id );

    current_box.style.opacity = 1;
    current_link.style.borderBottom = '2px solid #31baed';   

    // turn off

    if( vFlipB.previous_box !== undefined && vFlipB.previous_box !== current_box ) {
        vFlipB.previous_box.style.opacity = 0;
        vFlipB.previous_link.style.borderBottom = '';  
    }

    // set current to static previous

    vFlipB.previous_box = current_box;
    vFlipB.previous_link = current_link;
}

【问题讨论】:

  • 我们可以看看你剩下的代码吗,因为这部分很好
  • 无法解决问题..所以我只发布了代码的两个区域。
  • 为什么不把函数放在第299行之前呢?
  • 你在哪里调用了 jslint 的选项?
  • 只是 .js 文件顶部的注释 - /*jslint undef: false, browser: true */

标签: javascript jslint


【解决方案1】:

使用这个: /*jslint undef: true, sloppy: true, browser: true */

根据the docsundef 选项在严格模式下不可用。所以你需要设置sloppy: true(伟大的名字,嗯?)并从你的JS文件顶部删除任何"use strict";语句。 (您还反转了 undef 的值)。

当然有lots ofgood reasons可以使用严格模式。如果你想避免警告但仍然使用严格模式,你真的只有三个选择:

  • 使用 JSHint 代替 JSLint
  • "use strict"; 放置在每个单独的函数体的顶部,而不是文件或模块的顶部。 (你不能把它放在你调用 vFlipB() 的函数中——否则警告会回来)
  • 更改您的代码以避免调用下方定义的函数。你可以重新排序你的代码,把它分成单独的模块,或者玩这样的把戏:

    var vFlipB;
    ...
    vFlipB();
    ...
    vFlipB = function () { ... };
    

【讨论】:

    猜你喜欢
    • 2014-06-26
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 2023-03-28
    相关资源
    最近更新 更多