Skip to content

Commit 4ffc29a

Browse files
committed
ES6 WeakSet example
1 parent 3310956 commit 4ffc29a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

chapter07/11-ES6WeakSet.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script src="11-ES6WeakSet.js"></script>
9+
</body>
10+
</html>

chapter07/11-ES6WeakSet.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var set = new WeakSet();
2+
3+
var ob1 = {name:'Gandalf'},
4+
ob2 = {name:'John'},
5+
ob3 = {name:'Tyrion'};
6+
7+
set.add(ob1);
8+
set.add(ob2);
9+
set.add(ob3);
10+
11+
console.log(set.has(ob1)); //outputs true
12+
console.log(set.has(ob2)); //outputs true
13+
console.log(set.has(ob3)); //outputs true
14+
15+
set.delete(ob2);
16+
console.log(set.has(ob2)); //outputs false

0 commit comments

Comments
 (0)