Object.getOwnPropertyDescriptor()

このエントリーをはてなブックマークに追加

Object.getOwnPropertyDescriptor()はプロパティの現在の状態を確認できるメソッドです。

ECMAScript5で追加されたdefineProperty()を利用すればプロパティの付加情報を付けることができます。Object.getOwnPropertyDescriptor()はそのプロパティの状態を調べることができます。

Object.getOwnPropertyDescriptor()は第1引数でオブジェクトを第2引数でプロパティを指定できます。

var obj = {};
Object.defineProperty(obj,"prop",{
	value : "bar"
});
var propValue = Object.getOwnPropertyDescriptor(obj,"prop");
console.log(propValue);// {value: "bar", writable: false, enumerable: false, configurable: false}

確認できるのは付加情報は値(value)、列挙可能(enumerable)、削除可能(configurable)、変更可能(writable)の値です。

登録日 : 2015年08月13日 最終更新日 : 2015年8月13日

同じカテゴリー(Object)のエントリー

検索

スポンサードリンク

バージョン

リファレンス