最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ES Lint error for jQuery anonymous function - Stack Overflow

programmeradmin2浏览0评论

The code I have is as follows:

$('.panel').each( function() {
    $(this).css('height', 'auto');
    $(this).find('.portlet-panel-item').css('height', 'auto');
});

I am getting the following error: 37:26 warning Missing function expression name func-names.

I can't use the ES6 arrow functions because of the way this is being handled in the two use cases.

How can I fix this issue without having to put named functions for each?

The code I have is as follows:

$('.panel').each( function() {
    $(this).css('height', 'auto');
    $(this).find('.portlet-panel-item').css('height', 'auto');
});

I am getting the following error: 37:26 warning Missing function expression name func-names.

I can't use the ES6 arrow functions because of the way this is being handled in the two use cases.

How can I fix this issue without having to put named functions for each?

Share Improve this question asked Feb 17, 2017 at 16:23 Suthan BalaSuthan Bala 3,2995 gold badges40 silver badges61 bronze badges 2
  • You can't. You could just disable that check on that line. // eslint-disable-next-line func-name before it should do the trick. It's a linter, doesn't mean your code won't run or will cause errors, just that, if you agree with this rule, it's bad practice. – Sergiu Paraschiv Commented Feb 17, 2017 at 16:29
  • 1 Maybe you should read what the rule means first, then use your judgement as to whether the rule makes sense in this case. – Heretic Monkey Commented Feb 17, 2017 at 16:32
Add a ment  | 

1 Answer 1

Reset to default 5

You should either use a named function or disable the rule.

From 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.

You can set this rule to check "always", "as-needed", or "never" by using a ment, so in your case: /*eslint func-names: ["error", "never"]*/

发布评论

评论列表(0)

  1. 暂无评论