Rick Waldron (2014-03-05T16:11:21.000Z)
On Wed, Mar 5, 2014 at 7:04 AM, Sebastian Zartner <
sebastianzartner at gmail.com> wrote:

>    But it seems the thread fizzled out a couple years ago, and
>> Array.prototype.contains didn't seem to make its way into ES6. That seems
>> odd, since we do have String.prototype.contains, and it seemed like it was
>> desirable for DOM.
>>
>> The DOM won't inherit from it directly, shall it?
>>
>
> Why not? A use case would be to check whether a specific node is within a
> NodeList.
>
>>   It's also a standard utility function in several libraries.
>>
>>  Was it left out on purpose? If so, what was the justification?
>>
>> I predict code like this without it:
>>
>> ''.contains.call([1, 2, 3], 2);  // true
>>
>> .indexOf === -1 works today for this use case and will continue to.
>> I'd be happy to see !~arr.indexOf(el) disappear in favor of a use of
>> .contains() though.
>>
>
> While .indexOf() just gets you the index of one item, .contains() could
> even be extended to allow to check whether an array contains several items.
> E.g.
>
> .contains([1, 2, 3], [1, 3]) // true
> .contains([1, 2, 3], [1, 4]) // false
>


String.prototype.contains already has a second parameter for "position"
(similar to String.prototype.indexOf), for consistency an
Array.prototype.contains should have the same second "fromIndex" parameter
as Array.prototype.indexOf.

Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140305/c66208d2/attachment-0001.html>
domenic at domenicdenicola.com (2014-03-20T16:08:19.547Z)
On Wed, Mar 5, 2014 at 7:04 AM, Sebastian Zartner <sebastianzartner at gmail.com> wrote:

> While .indexOf() just gets you the index of one item, .contains() could
> even be extended to allow to check whether an array contains several items.
> E.g.
>
> ```js
> .contains([1, 2, 3], [1, 3]) // true
> .contains([1, 2, 3], [1, 4]) // false
> ```

String.prototype.contains already has a second parameter for "position"
(similar to String.prototype.indexOf), for consistency an
Array.prototype.contains should have the same second "fromIndex" parameter
as Array.prototype.indexOf.