在使用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