WeakSet

Estimated reading time: 1 minute

set

  • store reference
  • grabage
let set = new Set(),
    key = {null};
set.add(key);
console.log(set.size);
// 1

weakset

  • don’t store reference
  • no garbage
let set = new WeakSet(),
    key = {null};
set.add(key);
console.log(set.size);
// undefined
es, es6, js