[Map|Set|WeakMap].prototype.isEmpty()?

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Nov 2 10:32:02 PDT 2012


we are used to

`if (!arr.length) { .... }`

so I don't see much different with collections and `size()`

Said that, I have bad feelings when I read "empty()" thinking about all
other set of inconsistencies famous in PHP world :-)


On Fri, Nov 2, 2012 at 10:26 AM, Nicholas C. Zakas <
standards at nczconsulting.com> wrote:

> I had mentioned this in passing in a previous email, but wanted to bring
> it up again.
>
> As I've been playing more with maps and sets, I've come to realize that I
> do this a lot:
>
>     //note: FF implementation
>     if (set.size() === 0) { ... }
>
> Basically, the only thing I've ever done with the size of one of these
> structures is compare it against zero, meaning that I've only ever cared if
> the structure was empty not necessarily how many items were contained
> within.
>
> I don't know if it's worthwhile or not, but I would personally love to see
> isEmpty() as a method on Map, Set, and WeakMap (maybe Array and String,
> too?). It seems to go along nicely with the clear() method on Map, Set, and
> WeakMap.
>
> -N
>
> --
> ___________________________
> Nicholas C. Zakas
> http://www.nczonline.net
>
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121102/e90f1aa1/attachment.html>


More information about the es-discuss mailing list