I've been playing around with the Set prototypes in Firefox and Chrome
(knowing full well that they are incomplete and the spec hasn't been
finalized yet), and I wanted to share a couple of learnings.
First, since a Set can be initialized with an array, it stands to reason
that you should be able to easily get an array back from the set.
However, there is no way to do that right now short of using a loop and
manually constructing an array. I would really like to see a
*Set.prototype.toArray* method to easily change the Set back into an
array. A simple use case would be de-duping an array:
function dedupe(array) {
return (new Set(array)).toArray();
}
Second, the lack of visibility into Sets is problematic. A very simple
use case is when I want to see if the Set has been initialized yet but I
can't know what keys might have been used at that point in time. Firefox
implements a *Set.prototype.size* method which is useful to know what
I'm dealing with. However, I'm not sure how frequently the number of
items in the Set actually matters, so a *Set.prototype.isEmpty* would be
equally useful for this case.
Otherwise, I'm finding Sets very useful as a replacement for objects
that I was using for the same purpose.
Thanks,
Nicholas
--
___________________________
Nicholas C. Zakas
http://www.nczonline.net
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss