74

What does JSLint mean by this error? And how should it be rewritten?

Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function: })(jQuery);

Sam
  • 15,254
  • 25
  • 90
  • 145

1 Answers1

120

To pass JSLint's criteria, it needs to be written like this:

}(jQuery));

Though I think that particular criteria is a bit subjective. Both ways seem fine in my opinion.

(function () {})() makes a bit more sense to me since you wrap the full function, then call it

(function () {}()) looks like you're wrapping the result of the function call in a parens ...

Matt
  • 43,482
  • 6
  • 101
  • 102
  • 17
    What's JSLint's motivation for doing that? – Guffa Feb 12 '11 at 16:51
  • 1
    May I ask why? Most scripts in jQuery are of the format in the question post. – pimvdb Feb 12 '11 at 16:52
  • 1
    @Guffa + @pimvdb - not sure. Crockford usually expands a bit on [this page](http://www.jslint.com/lint.html), but it makes no mention of this. – Matt Feb 12 '11 at 16:53
  • 8
    http://stackoverflow.com/questions/1450721/solution-for-jslint-errors/1481517#1481517 – Marco Mariani Mar 18 '11 at 15:42
  • 1
    http://jslinterrors.com/move-the-invocation-into-the-parens-that-contain-the-function/ (not written by Douglas) says it's just a (lack of) convention – Jeroen Versteeg Apr 04 '13 at 07:42
  • 1
    You can use the "immed" option from [JSHint](http://stackoverflow.com/a/10763615/540352) if you want to allow both syntaxes. – Laoujin Jun 28 '13 at 22:34