Object.getOwnPropertyDescriptor()【プロパティディスクリプタ 取得】メソッド
メモ
- プロパティディスクリプタを取得
構文
- Object.getOwnPropertyDescriptor ( O, P )
- O:オブジェクト (オブジェクト以外はオブジェクト変換 )
- P:プロパティ名
プロパティディスクリプタ
TypeError 例外:O がオブジェクト以外
例
var point = { x:0, y:0 };
console.log(Object.getOwnPropertyDescriptor(point, 'x')); // Object {value: 0, writable: true, enumerable: true, configurable: true}
console.log(Object.getOwnPropertyDescriptor(point, 'y')); // Object {value: 0, writable: true, enumerable: true, configurable: true}
Object.defineProperty(point, 'x', { value:100, writable:false, enumerable:false });
console.log(Object.getOwnPropertyDescriptor(point, 'x')); // Object {value: 100, writable: false, enumerable: false, configurable: true}
console.log(Object.getOwnPropertyDescriptor(point, 'y')); // Object {value: 0, writable: true, enumerable: true, configurable: true}