Domanda

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?

È stato utile?

Soluzione

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 )
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top