2017-02-17 53 views
1

我的代碼如下:ES皮棉錯誤jQuery的匿名函數

$('.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的方式。

如何解決此問題,而不必爲每個命名函數?

+0

你可以「T。您可以在該行禁用該檢查。 '// eslint-disable-next-line func-name'在它應該做的訣竅之前。這是一個短消息,並不意味着你的代碼不會運行或將導致錯誤,只是如果你同意這個規則,這是不好的做法。 –

+1

也許你應該[先閱讀規則的含義](http://eslint.org/docs/rules/func-names),然後根據你的判斷來判斷規則在這種情況下是否有意義。 –

回答

1

您應該使用命名函數或禁用規則。

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檢查 「總是」,通過使用評論, 「按需」 或 「從不」 所以你的情況: /*eslint func-names: ["error", "never"]*/