课程: JavaScript: Maps and Sets

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

What is the WeakSet object?

What is the WeakSet object?

- [Instructor] The last lesson in this course is on WeakSet. The WeakSet is very closely related to Set, with some key differences. You can think about this relationship in the same manner that you did regarding Maps and WeakMaps. Just like Sets, WeakSets are a collection of objects that may occur only once within the given object, making them unique values. The main difference is that the reference to objects, here, are weak, as you might infer from the name. When we discussed WeakMaps, we briefly touched on the concept of garbage collection, which is a way of freeing up memory that has been allocated to objects no longer in use. With WeakSets, the same holds true. Because of its weak reference, the WeakSet can be garbage collected if there's no other reference to it. In terms of similarities, WeakSets and Sets both hold only unique values, and both have methods that allow you to add values, delete values, and check…

内容