no-wrap-func

不允许在函数表达式周围使用不必要的括号。

¥Disallows unnecessary parentheses around function expressions.

尽管可以将函数封装在括号中,但当代码还包含立即调用的函数表达式 (IIFE) 时,这可能会造成混淆,因为括号通常用于进行这种区分。例如:

¥Although it’s possible to wrap functions in parentheses, this can be confusing when the code also contains immediately-invoked function expressions (IIFEs) since parentheses are often used to make this distinction. For example:

var foo = (function() {
    // IIFE
}());

var bar = (function() {
    // not an IIFE
});

规则详情

¥Rule Details

此规则在遇到括在括号中且没有后续调用括号的函数表达式时将引发警告。

¥This rule will raise a warning when it encounters a function expression wrapped in parentheses with no following invoking parentheses.

此规则的错误代码示例:

¥Example of incorrect code for this rule:

var a = (function() {/*...*/});

此规则的正确代码示例:

¥Examples of correct code for this rule:

var a = function() {/*...*/};

(function() {/*...*/})();

版本

此规则是在 ESLint v0.0.9 中引入,并在 v1.0.0-rc-1 中删除。