jQuery 匿名函数的 ESLint 错误
ES Lint error for jQuery anonymous function
我的代码如下:
$('.panel').each( function() {
$(this).css('height', 'auto');
$(this).find('.portlet-panel-item').css('height', 'auto');
});
我收到以下错误:37:26 warning Missing function expression name func-names
。
我无法使用 ES6 箭头函数,因为 this
在两个用例中的处理方式。
如何解决这个问题而不必为每个函数添加命名函数?
您应该使用命名函数或禁用该规则。
来自AirBnB JavaScript style guide:
Don’t forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack.
您可以 set this rule 通过使用注释来检查 "always"、"as-needed" 或 "never",因此在您的情况下:
/*eslint func-names: ["error", "never"]*/
我的代码如下:
$('.panel').each( function() {
$(this).css('height', 'auto');
$(this).find('.portlet-panel-item').css('height', 'auto');
});
我收到以下错误:37:26 warning Missing function expression name func-names
。
我无法使用 ES6 箭头函数,因为 this
在两个用例中的处理方式。
如何解决这个问题而不必为每个函数添加命名函数?
您应该使用命名函数或禁用该规则。
来自AirBnB JavaScript style guide:
Don’t forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack.
您可以 set this rule 通过使用注释来检查 "always"、"as-needed" 或 "never",因此在您的情况下:
/*eslint func-names: ["error", "never"]*/