aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/object/getownpropertydescriptors/index.html
blob: 3579edc3d5e3c22109bf730e44b254037c22ae8f (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: Object.getOwnPropertyDescriptors()
slug: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors
tags:
  - JavaScript
  - Method
  - Object
translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors
---
<div>{{JSRef}}</div>

<p><code><strong>Object.getOwnPropertyDescriptors()</strong></code> メソッドは、指定したオブジェクトのすべてのプロパティ記述子を返します。</p>

<div>{{EmbedInteractiveExample("pages/js/object-getownpropertydescriptors.html")}}</div>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox notranslate">Object.getOwnPropertyDescriptors(<var>obj</var>)</pre>

<h3 id="Parameters" name="Parameters">引数</h3>

<dl>
 <dt><code>obj</code></dt>
 <dd>すべてのプロパティディスクリプタを取得するオブジェクト。</dd>
</dl>

<h3 id="Return_value" name="Return_value">返値</h3>

<p>オブジェクトのすべてのプロパティ記述子を含むオブジェクト。プロパティがない場合、空オブジェクトの可能性がある。</p>

<h2 id="Description" name="Description">説明</h2>

<p>このメソッドは、オブジェクトのすべての独自のプロパティの正確な記述の検査を可能にします。 JavaScript では、<dfn>プロパティ</dfn>は文字列値による名前または {{jsxref("Symbol")}} とプロパティ記述子で構成されています。プロパティ記述子の型と属性についての詳細情報は、{{jsxref("Object.defineProperty()")}} で確認してください。</p>

<p><dfn>プロパティディスクリプタ</dfn> は、次の属性のいくつかを持ちます。</p>

<dl>
 <dt><code>value</code></dt>
 <dd>プロパティに関連づけられた値です (データディスクリプタのみ)。</dd>
 <dt><code>writable</code></dt>
 <dd><code>true</code> である場合、プロパティに関連づけられた値は変更することができます (データ記述子のみ)。</dd>
 <dt><code>get</code></dt>
 <dd>プロパティのゲッターとして提供する関数、あるいはゲッターがない場合は {{jsxref("undefined")}} です (アクセサ記述子のみ)。</dd>
 <dt><code>set</code></dt>
 <dd>プロパティのセッターとして提供する関数、あるいはセッターがない場合は {{jsxref("undefined")}} です (アクセサ記述子のみ)。</dd>
 <dt><code>configurable</code></dt>
 <dd><code>true</code> である場合、この種の記述子を変更することや、対応するオブジェクトからプロパティを削除することができます。</dd>
 <dt><code>enumerable</code></dt>
 <dd><code>true</code> である場合、このプロパティは対応するオブジェクトでのプロパティ列挙に現れます。</dd>
</dl>

<h2 id="Examples" name="Examples"></h2>

<h3 id="Creating_a_shallow_clone" name="Creating_a_shallow_clone">浅いコピーの生成</h3>

<p>{{jsxref("Object.assign()")}} メソッドは、ソースオブジェクトから対象のオブジェクトに対して enumerable とプロパティのみコピーできる一方、2 つの未知のオブジェクト間の浅いコピーのために、このメソッドと {{jsxref("Object.create()")}} を使用できます:</p>

<pre class="brush: js notranslate">Object.create(
  Object.getPrototypeOf(obj),
  Object.getOwnPropertyDescriptors(obj)
);
</pre>

<h3 id="Creating_a_subclass" name="Creating_a_subclass">サブクラスの作成</h3>

<p>サブクラスを作成する通常の方法は、サブクラスを定義し、そのプロトタイプをスーパークラスのインスタンスに設定し、そのインスタンスにプロパティを定義することです。これは特にセッターやゲッターが無骨になることがあります。代わりに、プロトタイプを設定するためにこのコードを使用することもできます。</p>

<pre class="brush: js notranslate">function superclass() {}
superclass.prototype = {
  // Define your methods and properties here
};
function subclass() {}
subclass.prototype = Object.create(
  superclass.prototype,
  {
    // Define your methods and properties here
  }
);
</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-object.getownpropertydescriptors', 'Object.getOwnPropertyDescriptors')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<div>
<p>{{Compat("javascript.builtins.Object.getOwnPropertyDescriptors")}}</p>
</div>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{jsxref("Object.getOwnPropertyDescriptor()")}}</li>
 <li>{{jsxref("Object.defineProperty()")}}</li>
 <li><a href="https://github.com/tc39/proposal-object-getownpropertydescriptors">Polyfill</a></li>
</ul>