Array.prototype.contains

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Nov 2 18:23:49 PDT 2012


On Nov 2, 2012, at 5:45 PM, Brendan Eich wrote:

> Allen Wirfs-Brock wrote:
>>> "has" for keys (and possibly values of a Set, to preserve the value mapped to boolean future option that forEach also supports), "contains" for values in arrays
>> 
>> sounds ok, except we get the same issue for contains that we have for indexOf.  II guess the big thing with contains is that it can be applied no non-indexed collections (maps, sets, etc.).
> 
> I'm not sure there's enough of a problem with using contains (or indexOf) to justify splitting contains-names, which has its own problems (inconsistency with indexOf, also with other languages, _mutatis mutandis_, e.g. Java).

me neither...just a wart




> 
>> Also any reason contains should be provided for WeakMap? I not seeing why it shouldn't be there too.
> 
> How about Map contains (as well as has)?
> 
> How about Set for that matter?

Because people might actually use Map contains not realizing it isn't a near constant time probe like has.  But, that concern is offset by the disability  of having a consistent set of collection interfaces plus we don't like being a nannies.

I'd probably be on board with with having both for Set/Map/WeakMap


Allen 



More information about the es-discuss mailing list