Jslint无法识别错误排序函数的选项

时间:2012-08-18 19:15:58

标签: javascript jslint

我使用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;
        }

。 。

但是这里并不是默默无闻的。

on 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;
}

1 个答案:

答案 0 :(得分:1)

使用此: /*jslint undef: true, sloppy: true, browser: true */

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

当然,lots of good reasons使用严格模式。如果您想避免警告但仍然使用严格模式,那么您实际上只有三个选项:

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

    var vFlipB;
    ...
    vFlipB();
    ...
    vFlipB = function () { ... };
    
相关问题