blob: c7a096b6d9118ed63248ffeaa71898813174c310 (
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
|
---
title: WeakSet.prototype.add()
slug: Web/JavaScript/Reference/Global_Objects/WeakSet/add
tags:
- ECMAScript 2015
- JavaScript
- Method
- Prototype
- WeakSet
translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/add
---
<div>{{JSRef}}</div>
<p><strong><code>add()</code></strong> メソッドは、新しい要素を <code>WeakSet</code> オブジェクトの最後に追加します。</p>
<div>{{EmbedInteractiveExample("pages/js/weakset-prototype-add.html", "taller")}}</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"><var>ws</var>.add(<var>value</var>);</pre>
<h3 id="Syntax" name="Syntax">引数</h3>
<dl>
<dt><code><var>value</var></code></dt>
<dd>必須。 <code>WeakSet</code> コレクションに追加する要素の値です。</dd>
</dl>
<h3 id="Return_value" name="Return_value">返値</h3>
<p><code>WeakSet</code> オブジェクトです。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Using_add" name="Using_add">add() の使用</h3>
<pre class="brush: js notranslate">var ws = new WeakSet();
ws.add(window); //window オブジェクトを WeakSet へ追加
ws.has(window); // true
// WeakSet は引数としてオブジェクトのみを取ります。
ws.add(1);
// 結果は "TypeError: Invalid value used in weak set" (Chrome)
// "TypeError: 1 is not a non-null object" (Firefox)</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-weakset.prototype.add', 'WeakSet.prototype.add')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
<p>{{Compat("javascript.builtins.WeakSet.add")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("WeakSet")}}</li>
<li>{{jsxref("WeakSet.prototype.delete()")}}</li>
<li>{{jsxref("WeakSet.prototype.has()")}}</li>
</ul>
|