weakSet 基础应用实例 Map 应用基础实例

// weakSet 基础用法
let jelly = {name:'jelly',age:20};
let mary = {name:'mary',age:25};

const weakPeople = new WeakSet([jelly,mary])
console.log(weakPeople)
mary = null  //什么时间回收和各自的浏览器有关系。务必注意
console.log(weakPeople)

 

 

// Map 基础用法
const people = new Map();
people.set('Jelly', 23);
people.set('Ted', 23);
people.set('Mary', 23);

people.set({},3); 
people.get('Jelly') //23
console.log(people.size) //4
people.has('Jelly') //true  people.delete('Jelly')--删除Jelly
//people.clear() //清空
people.forEach(function(value,key,map){
    console.log(value,key,map)
})

 

……

posted @ 2019-12-28 21:04  问问大将军  阅读(167)  评论(0编辑  收藏  举报