2

我使用 JavaScript 注释来设置选项

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

根据此处的 jslint 文档容忍错误排序的函数和变量定义。我也尝试将其设置为“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;
}
4

1 回答 1

1

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

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

当然,使用严格模式有很多 很好的理由。如果你想避免警告但仍然使用严格模式,你真的只有三个选择:

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

    var vFlipB;
    ...
    vFlipB();
    ...
    vFlipB = function () { ... };
    
于 2013-04-23T20:01:29.893 回答