const weakm = new WeakMap();
let keyObject = {id : 1};
const valObject = {score : 100};
weakm.set(keyObject,valObject);
console.log(weakm.get(keyObject));
keyObject = null;
console.log(weakm);
console.log(weakm.get(keyObject));
打印结果:
为什么打印weakm还有键 {id:1},各位赐教
你这问题好比:
var a={id:1};
b=a;
a=null;
console.log(b);