i using following logic i18n string of given key.
export function i18n(key) { if (entries.hasownproperty(key)) { return entries[key]; } else if (typeof (canadarm) !== 'undefined') { try { throw error(); } catch (e) { canadarm.error(entries['databuildi18nstring'] + key, e); } } return entries[key]; } i using eslint in project. getting following error:
do not access object.prototype method 'hasownproperty' target object. 'no-prototype-builtins' error.
how change code resolve error ? don't want disable rule.
you can access via object.prototype:
object.prototype.hasownproperty.call(obj, prop); that should safer, because
- not objects inherit
object.prototype - even objects inherit
object.prototype,hasownpropertymethod shadowed else.
of course, code above assumes that
- the global
objecthas not been shadowed or redefined - the native
object.prototype.hasownpropertyhas not been redefined - no
callown property has been addedobject.prototype.hasownproperty - the native
function.prototype.callhas not been redefined
if of these not hold, attempting code in safer way, have broken code!
another approach not need call be
!!object.getownpropertydescriptor(obj, prop);
Comments
Post a Comment