-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path5-weak.js
More file actions
36 lines (26 loc) · 713 Bytes
/
Copy path5-weak.js
File metadata and controls
36 lines (26 loc) · 713 Bytes
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
'use strict';
const cities = new Set([
{ name: 'Beijing' },
{ name: 'Kiev' },
{ name: 'London' },
{ name: 'Baghdad' },
]);
const list = new WeakSet();
for (const city of cities) {
console.log('Add city', city, 'to WeakSet');
list.add(city);
}
console.dir({ cities, list });
const iterator = cities.values();
const beijing = iterator.next().value;
console.log('select', beijing);
iterator.next();
const london = iterator.next().value;
console.log('select', london);
cities.delete(london);
console.log('remove', london, 'from Set');
list.delete(beijing);
console.log('remove', beijing, 'from WeakSet');
for (const city of cities) {
console.log('City', city, 'in WeakSet', list.has(city));
}