suchen

Heim  >  Fragen und Antworten  >  Hauptteil

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 Tage vor285

Antworte allen(1)Ich werde antworten

  • 巴扎黑

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

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

    Antwort
    0
  • StornierenAntwort