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: WeakSet
slug: Web/JavaScript/Reference/Global_Objects/WeakSet
tags:
- ECMAScript 2015
- JavaScript
- Reference
- WeakSet
translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet
---
<div>{{JSRef}}</div>
<p><strong><code>WeakSet</code></strong> 객체는 약하게 유지되는(held, 잡아두는) <em>객체</em>를 컬렉션에 저장할 수 있습니다.</p>
<h2 id="구문">구문</h2>
<pre class="syntaxbox">new WeakSet([iterable]);</pre>
<h3 id="매개변수">매개변수</h3>
<dl>
<dt><code>iterable</code></dt>
<dd><a href="/ko/docs/Web/JavaScript/Reference/Statements/for...of">iterable 객체</a>가 전달된 경우, 모든 객체 요소는 새로운 <code>WeakSet</code>에 추가됩니다. null은 undefined로 취급됩니다.</dd>
</dl>
<h2 id="설명">설명</h2>
<p><code>WeakSet</code> 객체는 객체 컬렉션입니다. <code>WeakSet</code> 내 객체는 오직 한 번만 발생할 수 있습니다. 즉, <code>WeakSet</code> 컬렉션 내에서 유일합니다.</p>
<p>{{jsxref("Set")}} 객체와 주된 차이는 다음과 같습니다:</p>
<ul>
<li><code>Set</code>과 달리, <code>WeakSet</code>은 <strong>객체 만의 컬렉션</strong>이며 모든 유형의 임의 값(의 컬렉션)은 아닙니다.</li>
<li><code>WeakSet</code>은 약합니다(<em>weak</em>): 컬렉션 내 객체 참조는 약하게 유지됩니다. <code>WeakSet</code> 내 저장된 객체에 다른 참조가 없는 경우, 쓰레기 수집(garbage collection)될 수 있습니다. 이는 또한 컬렉션 내 현재 저장된 객체 목록이 없음을 뜻합니다. <code>WeakSets</code>은 열거불가입니다.</li>
</ul>
<h2 id="속성">속성</h2>
<dl>
<dt><code>WeakSet.length</code></dt>
<dd><code>length</code> 속성값은 0.</dd>
<dt>{{jsxref("WeakSet.prototype")}}</dt>
<dd><code>Set</code> 생성자에 대한 프로토타입을 나타냅니다. 모든 <code>WeakSet</code> 객체에 속성을 추가할 수 있습니다.</dd>
</dl>
<h2 id="WeakSet_인스턴스"><code>WeakSet</code> 인스턴스</h2>
<p>모든 <code>WeakSet</code> 인스턴스는 {{jsxref("WeakSet.prototype")}}에서 상속합니다.</p>
<h3 id="속성_2">속성</h3>
<p>{{page('ko/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/prototype','속성')}}</p>
<h3 id="메서드">메서드</h3>
<p>{{page('ko/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/prototype','메서드')}}</p>
<h2 id="예제">예제</h2>
<h3 id="WeakSet_객체_사용"><code>WeakSet</code> 객체 사용</h3>
<pre class="brush: js">var ws = new WeakSet();
var obj = {};
var foo = {};
ws.add(window);
ws.add(obj);
ws.has(window); // true
ws.has(foo); // false, foo가 집합에 추가되지 않았음
ws.delete(window); // 집합에서 window 제거함
ws.has(window); // false, window가 제거되었음
</pre>
<h2 id="명세">명세</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">명세</th>
<th scope="col">상태</th>
<th scope="col">설명</th>
</tr>
<tr>
<td>{{SpecName('ES2015', '#sec-weakset-objects', 'WeakSet')}}</td>
<td>{{Spec2('ES2015')}}</td>
<td>초기 정의.</td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-weakset-objects', 'WeakSet')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="브라우저_호환성">브라우저 호환성</h2>
<p>{{Compat("javascript.builtins.WeakSet")}}</p>
<h2 id="같이_보기">같이 보기</h2>
<ul>
<li>{{jsxref("Map")}}</li>
<li>{{jsxref("Set")}}</li>
<li>{{jsxref("WeakMap")}}</li>
</ul>
|