Introduction
Before ES6, Javascript had no native implementation of Sets. What is a set? A set is a list of values that cannot contain d...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for the post Damien. You should do a follow up on
Maps
,WeakMaps
. Maybe go into explaining howWeakmaps
are great for meta data.Thank for the comment. I'm working on it ;)
Thanks for the post. The last example is a little confusing to me: When setting
obj = null
, and afterwards testing withset.has(obj)
, I would expect the set to return false even if it still contains{}
(the object), as the test is equal toset.has(null)
and you never addednull
to the set. Or am I wrong?In that last example, we added a reference to the object, inside the variable
obj
. By settingobj
to null, we eliminate the last reference to the object we stored in our set. Therefore, because this is a WeakSet, the object is garbage-collected in order to free memory.Hope it's clear :)
Probably the cleanest cover image you've had Damian! 😋
I never took the time to actually learn what "weak" things were. Thanks :D