Do not perform functions inside a loop. - jslint error

I get this jslint error

Do not perform functions inside a loop.

I can’t change the javascript that causes this problem, but I can’t because of the restrictions on modifying it.

So, I want to rotate this check to check this error in a specific javascript file.

Can this be done for this js error?

+4
source share
1 answer

No, this validation check is optional.

Possible workaround:

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

Decision:

// 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);
}
+7
source

All Articles