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

David Bruant bruant.d at gmail.com
Fri Nov 2 10:30:48 PDT 2012


It does not apply to WeakMaps, but otherwise, I agree it's a nice method
to have on Map and Set.

David

Le 02/11/2012 18:26, Nicholas C. Zakas a écrit :
> 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
>



More information about the es-discuss mailing list