File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const cities = new Set ( [
4+ { name : 'Beijing' } ,
5+ { name : 'Kiev' } ,
6+ { name : 'London' } ,
7+ { name : 'Baghdad' }
8+ ] ) ;
9+
10+ const list = new WeakSet ( ) ;
11+ for ( const city of cities ) {
12+ console . log ( 'Add city' , city , 'to WeakSet' ) ;
13+ list . add ( city ) ;
14+ }
15+
16+ console . dir ( { cities, list } ) ;
17+
18+ const iterator = cities . values ( ) ;
19+
20+ const beijing = iterator . next ( ) . value ;
21+ console . log ( 'select' , beijing ) ;
22+
23+ iterator . next ( ) ;
24+
25+ const london = iterator . next ( ) . value ;
26+ console . log ( 'select' , london ) ;
27+
28+ cities . delete ( london ) ;
29+ console . log ( 'remove' , london , 'from Set' ) ;
30+
31+ list . delete ( beijing ) ;
32+ console . log ( 'remove' , beijing , 'from WeakSet' ) ;
33+
34+ for ( const city of cities ) {
35+ console . log ( 'City' , city , 'in WeakSet' , list . has ( city ) ) ;
36+ }
You can’t perform that action at this time.
0 commit comments