Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day56:介绍下Set、Map、WeakSet和WeakMap的区别 #104

Closed
lgwebdream opened this issue Jul 6, 2020 · 2 comments
Closed

Day56:介绍下Set、Map、WeakSet和WeakMap的区别 #104

lgwebdream opened this issue Jul 6, 2020 · 2 comments

Comments

@lgwebdream
Copy link
Owner

No description provided.

@lgwebdream
Copy link
Owner Author

扫描下方二维码,获取答案以及详细解析,同时可解锁800+道前端面试题。

@Genzhen Genzhen closed this as completed Jul 22, 2020
@LiSiQinF
Copy link

// 答案与解析
1)Set
成员唯一、无序且不重复;
[value, value],键值与键名是一致的(或者说只有键值,没有键名);
可以遍历,方法有:add、delete、has。

2)WeakSet
成员都是对象;
成员都是弱引用,可以被垃圾回收机制回收,可以用来保存DOM节点,不容易造成内存泄漏;
不能遍历,方法有 add、delete、has。

3)Map
本质上是键值对的集合,类似集合;
可以遍历,方法很多,可以跟各种数据格式转换。

4)WeakMap
只接受对象作为键名(null 除外),不接受其他类型的值作为键名;
键名是弱引用,键值可以是任意的,键名所指向的对象可以被垃圾回收,此时键名是无效的;
不能遍历,方法有 get、set、has、delete。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants