hasOwnProperty
Object.hasOwnProperty()はプロパティが継承されているか確認できるメソッドです。
Objectはプロトタイプオブジェクトから継承した値を保持しています。Object.hasOwnProperty()を利用することでオブジェクトが独自に定義したオブジェクトかプロトタイプオブジェクトから継承したオブジェクトが確認できます。
var o = {a:"b"};
o.hasOwnProperty("a");//true
o.hasOwnProperty("constructor");//false
この場合、”a”は独自に定義した値なのでtrueを返し、constructorはオブジェクトがプロトタイプオブジェクトより継承したプロパティなのでfalseを返します。
登録日 : 2013年06月01日 最終更新日 : 2013年6月1日
同じカテゴリー(Object)のエントリー
- Object.create()
- Object.getPrototypeOf()
- Object.isFrozen()
- Object.freeze()
- Object.isSealed()
- Object.seal()
- Object.isExtensible()
- Object.preventExtensions()
- Object.getOwnPropertyDescriptor()
- Object.defineProperties()
- Object.defineProperty()
- keys()
- valueOf()
- toString()
- toLocaleString()
- propertyisEnumerable()
- isProtoTypeOf()
- hasOwnProperty
- constructor