<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="Width = device - width, initial - scale = 1.0">
<title>Document</title>
</head>
<body>
<script>
let set = new WeakSet(a)let key = {}
set.add(key)
console.log(set.has(key)) //true
key = { a: 1 } // Remove the first reference to key and add a new reference
console.log(set.has(key)) //false, Weak Set references are automatically removed
</script>
</body>
</html>
Copy the code