JS 在使用hasOwnProperty()函數時報錯


在使用hasOwnProperty()方法判斷對象是否具有某種屬性時eslint報下列錯誤:
Do not access Object.prototype method 'hasOwnProperty' from target object.eslintno-prototype-builtins
ESLINT修改了規則,禁止state.hasOwnProperty(key) 這樣判斷
修改規則前是這樣判斷:

修改規則后是這樣判斷:

所以修改代碼為:


參考資料:
https://zhuanlan.zhihu.com/p/118126825
https://host.zzidc.com/wljc/1297.html






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM