search

Home  >  Q&A  >  body text

javascript - WeakMap

  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},各位赐教

天蓬老师天蓬老师2774 days ago287

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-11 12:22:44

    你这问题好比:
    var a={id:1};
    b=a;
    a=null;
    console.log(b);

    reply
    0
  • Cancelreply