views:

718

answers:

3

Hey, I have started using JSLint,And I checked my code and I am getting this errors:

Problem at line 92 character 7: Move the invocation into the parens that contain the function.

})();

Problem at line 92 character 7: Wrap the entire immediate function invocation in parens.

})();

How To Fix this errors?

+12  A: 

I believe this means you should move the function calling parens inside the wrapping parens

(function() { /* code */ })()

The two last parens that execute the function are the problem. This is how jslint wants it to look like:

(function() { /* code */ }())
Jani Hartikainen
That's strange. The convention is usually to wrap everything before last invocation parens - `(function(){})()`.
kangax
Well, since when did jslint make complete sense? ;) Personally I just ignore the rules which don't make sense, such as this one.
Jani Hartikainen
"since when did jslint make complete sense?", I know that was made in jest, but every rule that crockford put in there has some lengthy justification. You could say that many of the rules aren't very important, but the rules, at least, have a solid justification.
Mark Rogers
A: 

Thanks Jani , Fixed The Problem :D

Yosy
You can accept my answer if it was correct ;)
Jani Hartikainen
+6  A: 

I found a good explanation here: http://james.padolsey.com/javascript/closures-in-javascript/

The first set of parentheses (around "function(){}") isn't required but is used to make it obvious that the function is immediately invoked, thus making it obvious that the expression does not necessarily return that function; but instead the return value of that function

Rob
This makes perfect sense, especially when it's a big function. It makes it very obvious what's going on - something that helps when reading the code another person wrote, or your own code after 3 months of not looking at it. Code, after all, is read much more often than it is written.
Tim Kersten