Javascript JSLint 错误:“将调用移动到包含函数的括号中”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4979252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSLint error: "Move the invocation into the parens that contain the function"
提问by Sam
What does JSLintmean by this error? And how should it be rewritten?
JSLint这个错误是什么意思?以及应该如何改写?
Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function:
})(jQuery);
Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function:
})(jQuery);
回答by Matt
To pass JSLint's criteria, it needs to be written like this:
要通过 JSLint 的标准,需要这样写:
}(jQuery));
}(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 () {})()
对我来说更有意义,因为你包装了完整的函数,然后调用它
(function () {}())
looks like you're wrapping the result of the function call in a parens ...
(function () {}())
看起来您正在将函数调用的结果包装在括号中...