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) {
alert(a);
}(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) {
alert(a);
}(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
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.
[...] literal, and instead saw '{a}'. Expected to see a statement and instead saw a block. Extra comma. Function statements are not invocable. Wrap the function expression in parens. Function statements should not be placed in blocks. Use a function expression or move the statement [...]
[...] is similar to another wordy JavaScript message: Function statements are not invocable. Wrap the whole function invocation in parens, which captures isolated unwrapped function declarations. Seen in the following [...]
[...] above is equivalent to the first sample of code, and will execute in exactly the same way. JSLint encourages you to wrap invoked function expressions with parentheses. Wrapping non-invoked function expressions in the same way may be indicative of something [...]