4

このjslintエラーが発生します

ループ内で関数を作成しないでください。

この問題の原因となっているJavaScriptを変更することはできませんが、変更の制限により変更できません。

したがって、この検証をオフにして、特定のjavascriptファイルでこのエラーをチェックしたいと思います。

このjsエラーに対してこれを行うことは可能ですか?

4

1 に答える 1

8

いいえ、その検証チェックはオプションではありません。

考えられる回避策:

// simple closure scoping i to the function.
for(var i = 0; i < 10; i++) {
    (function (index) {
         console.log(index);
     }(i));
}
// this works, however it's difficult to site read and not a blast to debug

解決策:

// same exact output
function logger(index) {
    console.log(index);
}

// same output. Minus declaring all vars at the
// top of the function and console this passes jslint.
for(var i = 0; i < 10; i++) {
    logger(i);
}
于 2011-07-28T21:31:34.293 に答える