Array.prototype.contains

Jason Orendorff jason.orendorff at gmail.com
Fri Nov 2 10:56:19 PDT 2012


On Fri, Nov 2, 2012 at 12:29 PM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:

> > If we call it "has", should we also rename String.prototype.contains?
>
> I'd say no; the distinction between collections "having" an element and
> strings "containing" a substring seems very sensible. It's a bit more
> awkward to say a string "has" a substring, and a string is definitely not a
> collection of substrings in any reasonable sense.
>

Well, you could also note that array.has(x) looks for a particular value,
while map.has(x) looks for a particular key.

But that's not the point. There's no common formal contract implemented by
all these methods; what they share is an informal "hey, look in this thing,
and tell me if you see that thing" vibe.

I like the idea of being able to say str.has(",") or str.has("=>") or
str.has("@jorendorff") and have them all just work.

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121102/8960e4a3/attachment.html>


More information about the es-discuss mailing list