forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweakset.jsdoc
More file actions
137 lines (94 loc) · 2.9 KB
/
weakset.jsdoc
File metadata and controls
137 lines (94 loc) · 2.9 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
WeakSet : Object
WeakSets are a collection of %%/Object|Objects%% where each
object can only appear once in the set similar to %%/Set|Set%%.
Unlike Set, WeakSet does not allow iterating over its values.
If WeakSet would be the only object holding on to the value,
the value will be released from memory.
The values stored in WeakSet cannot be primitive values
(%%/Boolean|Boolean%%,
%%/Number|Number%%,
%%/String|String%%,
or
%%/undefined|undefined%%).
Version:
ECMAScript 2015
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset-objects
----
new WeakSet() : WeakSet
Creates an empty WeakSet.
<example>
var value1 = { foo: 1 };
var value2 = { bar: ['a', 'b', 'c'] };
var x = new WeakSet();
x.add(value1);
console.log(x.has(value1));
console.log(x.has(value2));
</example>
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset-iterable
----
new WeakSet(iterable : Object) : WeakSet
Creates a WeakSet by iterating over **iterable** and adding
each value to the WeakSet.
<example>
var value1 = { foo: 1 };
var value2 = { bar: ['a', 'b', 'c'] };
var fromArray = new WeakSet([value1, value2]);
console.log(fromArray.has(value1));
console.log(fromArray.has(value2));
var generator = function*() {
yield value1;
yield value2;
};
var fromGenerator = new WeakSet(generator());
console.log(fromGenerator.has(value1));
console.log(fromGenerator.has(value2));
</example>
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset-iterable
----
prototype.add(value : Object) : Set
Stores **value** in **this**. If **value** is already stored,
there is no change to the WeakSet.
Returns **this**.
<example>
var value1 = { foo: 1 };
var value2 = { bar: ['a', 'b', 'c'] };
var x = new WeakSet([value1]);
console.log(x.has(value1));
console.log(x.has(value2));
x.add(value2);
console.log(x.has(value2));
</example>
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset.prototype.add
----
prototype.delete(value : Object) : Boolean
Removes **value** from **this**.
Returns **true** if **value** was in **this** before deleting it.
<example>
var value1 = { foo: 1 };
var value2 = { bar: ['a', 'b', 'c'] };
var x = new WeakSet([value1, value2]);
console.log('has value1 = ' + x.has(value1));
console.log('has value2 = ' + x.has(value2));
console.log('deleted value2 = ' + x.delete(value2));
console.log('has value1 = ' + x.has(value1));
console.log('has value2 = ' + x.has(value2));
console.log('deleted value2 = ' + x.delete(value2)); // Already deleted
</example>
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset.prototype.delete
----
prototype.has(value : Object) : Boolean
Returns **true** if the set contains **value**.
<example>
var value1 = { foo: 1 };
var value2 = { bar: ['a', 'b', 'c'] };
var x = new WeakSet([value1]);
console.log(x.has(value1));
console.log(x.has(value2));
</example>
Spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-weakset.prototype.has