1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
---
title: Reflect.getOwnPropertyDescriptor()
slug: Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor
tags:
- ECMAScript 2015
- JavaScript
- Method
- Reference
- Reflect
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor
---
<div>{{JSRef}}</div>
<p><span class="seoSummary">静的な <strong><code>Reflect.getOwnPropertyDescriptor()</code></strong> メソッドは {{jsxref("Object.getOwnPropertyDescriptor()")}} と似ています。オブジェクトにプロパティが存在する場合は、指定されたプロパティのプロパティ記述子を返します。一方、プロパティが存在しない場合は {{jsxref("undefined")}} を返します。</span></p>
<div>{{EmbedInteractiveExample("pages/js/reflect-getownpropertydescriptor.html")}}</div>
<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox notranslate">Reflect.getOwnPropertyDescriptor(<var>target</var>, <var>propertyKey</var>)
</pre>
<h3 id="Parameters" name="Parameters">引数</h3>
<dl>
<dt><code><var>target</var></code></dt>
<dd>プロパティを探す対象のオブジェクト。</dd>
<dt><code><var>propertyKey</var></code></dt>
<dd>所有しているプロパティ記述子を取得するためのプロパティ名。</dd>
</dl>
<h3 id="Return_value" name="Return_value">返値</h3>
<p><code><var>target</var></code> オブジェクト内にプロパティが存在する場合は、プロパティ記述子オブジェクト、または {{jsxref("undefined")}}。</p>
<h3 id="Exceptions" name="Exceptions">例外</h3>
<p>{{jsxref("TypeError")}}: <code><var>target</var></code> が {{jsxref("Object")}} ではない場合</p>
<h2 id="Description" name="Description">解説</h2>
<p><code>Reflect.getOwnPropertyDescriptor</code> オブジェクトにプロパティが存在する場合、与えられたプロパティのプロパティディスクリプタを返します。一方、プロパティが存在しない場合は、{{jsxref("undefined")}} を返します。{{jsxref("Object.getOwnPropertyDescriptor()")}} との唯一の違いは、非オブジェクトの対象がどのようにバンドルされるかだけです。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Using_Reflect.getOwnPropertyDescriptor" name="Using_Reflect.getOwnPropertyDescriptor">Reflect.getOwnPropertyDescriptor() の使用</h3>
<pre class="brush: js notranslate">Reflect.getOwnPropertyDescriptor({x: 'hello'}, 'x')
// {value: "hello", writable: true, enumerable: true, configurable: true}
Reflect.getOwnPropertyDescriptor({x: 'hello'}, 'y')
// undefined
Reflect.getOwnPropertyDescriptor([], 'length')
// {value: 0, writable: true, enumerable: false, configurable: false}
</pre>
<h3 id="Difference_to_Object.getOwnPropertyDescriptor" name="Difference_to_Object.getOwnPropertyDescriptor">Object.getOwnPropertyDescriptor() との違い</h3>
<p>このメソッドへの最初の引数がオブジェクトではない (プリミティブであった) 場合、 {{jsxref("TypeError")}} が発生します。 {{jsxref("Object.getOwnPropertyDescriptor")}} だと、非オブジェクトである最初の引数は強制的にオブジェクトに変換されます。</p>
<pre class="brush: js notranslate">Reflect.getOwnPropertyDescriptor('foo', 0)
// TypeError: "foo" is not non-null object
Object.getOwnPropertyDescriptor('foo', 0)
// { value: "f", writable: false, enumerable: true, configurable: false }</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-reflect.getownpropertydescriptor', 'Reflect.getOwnPropertyDescriptor')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("javascript.builtins.Reflect.getOwnPropertyDescriptor")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Reflect")}}</li>
<li>{{jsxref("Object.getOwnPropertyDescriptor()")}}</li>
</ul>
|