'hasOwnProperty' in javascript -


i use obj.hasownproperty judge whether object has property, when replaced obj[prop] !== undefined, not normal implementation, ask, why behind method can not use it?

object.hasownproperty(prop); object[prop] !== undefined; 

obj[prop] !== undefined wrong 2 reasons:

  1. you can explicitly set property undefined, obj[prop] = undefined;. obj.hasownproperty(prop) return true in case.
  2. obj[prop] follow prototype chain, return property that's inherited. obj.hasownproperty(prop) returns true if property exists directly in object, returns false inherited properties.

Comments

Popular posts from this blog

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

Command prompt result in label. Python 2.7 -