I am attempting to rewrite a plug-in so that it will pass JSLint. I'm about 3 lines into a 300 line script, and I'm stuck here:
var __slice = [].slice,
__indexOf = [].indexOf || function (item) {
var i = 0,
l = this.length;
for (i < l) <<<<< this is where the error is
{
if (i in this && this[i] === item)
return i;
}
i+=1;
return -1;};
The error is
"Expected ';' and instead saw ')'.
for (i < l)
I'm not sure how to rewrite this to fit their conventions. Suggestions?
This is not a problem related to JSLint, but your for loop syntax is incorrect.
The syntax for a for loop looks like this:
for (initialization; condition; increment);
an example:
for (var i = i; i < 10; i++)
So in your situation you should either use:
for (; i < L ;)
Notice the omitting of the initialization and increment part.
Or better yet, use a while loop:
while ( i < L )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.