JSLint Messages – Function statements are not invocable. Wrap the whole function invocation in parens.

With this message we take a look at JavaScript closures. Without wanting to engage into a discussion about what they or their relative merits are, we can examine how this message might arise. Take the following code:

var a = 0;
(function(a) {

The parentheses around the function are necessary, because when omitted, the compiler assumes it is a Function Statement (see links below).When omitted, our code looks like this:

var a = 0;
function(a) {

This code is incorrect and will fail to execute.

In addition to this message you will also receive the message “Missing name in function statement.”

Some Links

For more information on closures, refer to Closures in JavaScript by James Padolsey.

The above function code follows a convention more commonly known as the JavaScript Module Pattern

To demystify the mire of Function Declarations, Function Expressions and Function Statements, refer the article Named function expressions demystified by Juriy “kangax” Zaytsev.

Also thanks to StackOverflow for helping me answer this: Question – Solution for JSLint Errors

Be careful where you place your parentheses. You may get another JSLint message Move the invocation into the parens that contain the function.

A Guide To JSLint Messages

This article is one of a series on the error and warning messages produced by JSLint.