【JSリファレンス】Reflect.getOwnPropertyDescriptor()

更新日:2024/06/14

Reflect.getOwnPropertyDescriptor()は、Reflectオブジェクトのメソッドです。

プロパティからプロパティ記述子を取得して返します。

同じ機能を持つObject.getOwnPropertyDescriptor()はオブジェクト以外の値を対象とした場合オブジェクトに変換します。
Reflect.getOwnPropertyDescriptor()は、TypeError です。

 

■構文

Reflect.getOwnPropertyDescriptor ( target, propertyKey )
  1. target: 対象となるオブジェクト

    オブジェクト以外を指定した場合TypeError

  2. propertyKey: 文字列またはシンボル

    プロパティ名を指定する

プロパティのプロパティ記述子

プロパティが存在しない場合はundefined。

 

■使用例

const obj = {param1:100}

const result = 
  Reflect.getOwnPropertyDescriptor( obj , "param1" );
console.log( result );

const result2 = 
  Reflect.getOwnPropertyDescriptor( obj , "param2" );
console.log( result2 );

// 結果:
// { value: 100, writable: true, enumerable: true, configurable: true }
// undefined

更新日:2024/06/14

書いた人(管理人):けーちゃん

スポンサーリンク

記事の内容について

null

こんにちはけーちゃんです。
説明するのって難しいですね。

「なんか言ってることおかしくない?」
たぶん、こんなご意見あると思います。

裏付けを取りながら記事を作成していますが、僕の勘違いだったり、そもそも情報源の内容が間違えていたりで、正確でないことが多いと思います。
そんなときは、ご意見もらえたら嬉しいです。

掲載コードについては事前に動作確認をしていますが、貼り付け後に体裁を整えるなどをした結果動作しないものになっていることがあります。
生暖かい視線でスルーするか、ご指摘ください。

ご意見、ご指摘はこちら。
https://jsref.affi-sapo-sv.com/info.php

 

このサイトは、リンクフリーです。大歓迎です。