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

143.[js]介绍下 Set、Map、WeakSet 和 WeakMap 的区别? #143

Open
webVueBlog opened this issue Mar 31, 2020 · 1 comment
Open

143.[js]介绍下 Set、Map、WeakSet 和 WeakMap 的区别? #143

webVueBlog opened this issue Mar 31, 2020 · 1 comment
Labels
JavaScript JavaScript

Comments

@webVueBlog
Copy link
Member

[软技能]

@webVueBlog webVueBlog added the JavaScript JavaScript label Mar 31, 2020
@webVueBlog
Copy link
Member Author

Set
成员唯一、无序且不重复;
[value, value],键值与键名是一致的(或者说只有键值,没有键名);
可以遍历,方法有:add、delete、has。
WeakSet
成员都是对象;
成员都是弱引用,可以被垃圾回收机制回收,可以用来保存 DOM 节点,不容易造成内存泄漏;
不能遍历,方法有 add、delete、has。
Map
本质上是键值对的集合,类似集合;
可以遍历,方法很多,可以跟各种数据格式转换。
WeakMap
只接受对象最为键名(null 除外),不接受其他类型的值作为键名;
键名是弱引用,键值可以是任意的,键名所指向的对象可以被垃圾回收,此时键名是无效的;
不能遍历,方法有 get、set、has、delete。

@webVueBlog webVueBlog changed the title 143.[软技能]介绍下 Set、Map、WeakSet 和 WeakMap 的区别? 143.[js]介绍下 Set、Map、WeakSet 和 WeakMap 的区别? Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScript JavaScript
Projects
None yet
Development

No branches or pull requests

1 participant