Array.prototype.contains

Mark S. Miller erights at google.com
Fri Nov 2 11:55:30 PDT 2012


Fortunately, strings cannot contain -0.0 or NaN, so neither string.contains
nor string.has sets any relevant precedent. FWIW, neither does
string.indexOf nor string.lastIndexOf.

The only consistency issue is: should array.has agree with sense and all
other collections, or should it agree with array.indexOf / lastIndexOf.
FWIW, I would prefer not to add any more conveniences that further entrench
unexpected === checks.


    [NaN].has(NaN) // false

makes little sense.

    [0.0].has(-0.0) // true

makes somewhat more sense, but not enough. Please let's either use add
"has" using SameValue or not add anything at all.



On Fri, Nov 2, 2012 at 11:04 AM, Rick Waldron <waldron.rick at gmail.com>wrote:

>
> On Friday, November 2, 2012 at 1:56 PM, Jason Orendorff wrote:
>
> 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.
>
> This is definitely nice :)
>
> Jason, Erik, Mark,
>
> Any specific thoughts about the SameValue case as it likely doesn't apply
> to a hypothetical String.prototype.has impl.? I suspect that a string had
> would still use indexOf which would introduce an internal inconsistency for
> the sake of API consistency (which I'm all for). Unless I'm overlooking?
>
> Rick
>
>
>
> -j
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121102/3f237e37/attachment-0001.html>


More information about the es-discuss mailing list