admin管理员组文章数量:1332389
I've got a problem with ESLint
Here is my function:
$productItem.filter(function (i, el) {
return el.getBoundingClientRect().top < evt.clientY
}).last()
.after($productItemFull)
And Here is what ESLint tell me:
warning Missing function expression name func-names
error Unexpected function expression prefer-arrow-callback
How to solve this error?
I've got a problem with ESLint
Here is my function:
$productItem.filter(function (i, el) {
return el.getBoundingClientRect().top < evt.clientY
}).last()
.after($productItemFull)
And Here is what ESLint tell me:
warning Missing function expression name func-names
error Unexpected function expression prefer-arrow-callback
How to solve this error?
Share edited Jul 6, 2016 at 11:21 Tushar 87.2k21 gold badges163 silver badges181 bronze badges asked Jul 6, 2016 at 10:26 StanouuStanouu 1301 silver badge8 bronze badges2 Answers
Reset to default 7It is basically saying to use Arrow function syntax in the filter
callback function.
$productItem.filter((i, el) => el.getBoundingClientRect().top < evt.clientY)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.last()
.after($productItemFull);
Here's what ESLINT documentation for prefer-arrow-callback
says
Arrow functions are suited to callbacks, because:
this
keywords in arrow functions bind to the upper scope’s.The notation of the arrow function is shorter than function expression’s.
And, in following cases the error will be thrown
/*eslint prefer-arrow-callback: "error"*/ foo(function(a) { return a; }); foo(function() { return this.a; }.bind(this));
Your code is same same as the first snippet. So, the error prefer-arrow-callback
is shown by ESLint.
To solve the error, you can
use Arrow function syntax(as shown above)
Suppress the error by using options and named function
/*eslint prefer-arrow-callback: ["error", { "allowNamedFunctions": true }]*/ foo(function bar() {});
to solve "unexpected function expression. (prefer-allow-callback)" error in eslint write this code in the beginning of your code:
/*eslint prefer-arrow-callback: 0*/
本文标签: javascriptESLint preferarrowcallback errorStack Overflow
版权声明:本文标题:javascript - ESLint prefer-arrow-callback error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742290728a2447745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论