TEL - 15 : o not access Object.prototype method 'hasOwnProperty' from target object

TEL - 15 : o not access Object.prototype method 'hasOwnProperty' from target object

Javascript


  • SITUATION :

    • 객체에 해당 프로퍼티가 존재하는지 확인 하는 메소드를 작성 하려고 hasOwnProperty를 사용

    o not access Object.prototype method 'hasOwnProperty' from target object.
    라는 메세지가 출력 되고 실행 되지 않음

  • REASON :

    • eslint의 no-prototype-builtins 라는 규칙에 의해 에러를 발생
      Object.prototype의 builtin으로 제공 되는 메서드는 객체에서 직접 호출하지 않도록 하는 규칙이 있다.
  • SOLUTION :

    • Object.prototype.hasOwnProperty.call(foo, ‘bar’) 처럼 사용해야 한다.

© 2022.02 by sunnyfterrain