{"id":599,"hash":"f26222c76e02025af9ee1d9ef6b4efc3c5d48d9acc506c1604778ec080811d4e","pattern":"Object.hasOwnProperty() yields the ESLint &#39;no-prototype-builtins&#39; error: how to fix?","full_message":"I am using the following logic to get the i18n string of the given key.\n\nexport function i18n(key) {\n  if (entries.hasOwnProperty(key)) {\n    return entries[key];\n  } else if (typeof (Canadarm) !== 'undefined') {\n    try {\n      throw Error();\n    } catch (e) {\n      Canadarm.error(entries['dataBuildI18nString'] + key, e);\n    }\n  }\n  return entries[key];\n}\n\nI am using ESLint in my project. I am getting the following error:\n\n  Do not access Object.prototype method 'hasOwnProperty' from target object.\n  It is a 'no-prototype-builtins' error. \n\nHow do I change my code to resolve this error ? I don't want to disable this rule.","ecosystem":"npm","package_name":"ecmascript-6","package_version":null,"solution":"You can access it via Object.prototype:\n\nObject.prototype.hasOwnProperty.call(obj, prop);\n\nThat should be safer, because\n\nNot all objects inherit from Object.prototype\nEven for objects which inherit from Object.prototype, the hasOwnProperty method could be shadowed by something else.\n\nOf course, the code above assumes that\n\nThe global Object has not been shadowed or redefined\nThe native Object.prototype.hasOwnProperty has not been redefined\nNo call own property has been added to Object.prototype.hasOwnProperty\nThe native Function.prototype.call has not been redefined\n\nIf any of these does not hold, attempting to code in a safer way, you could have broken your code!\n\nAnother approach which does not need call would be\n\n!!Object.getOwnPropertyDescriptor(obj, prop);","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/39282873/object-hasownproperty-yields-the-eslint-no-prototype-builtins-error-how-to","votes":330,"created_at":"2026-04-19T04:51:24.111598+00:00","updated_at":"2026-04-19T04:51:24.111598+00:00"}