Array.prototype.contains
Mark S. Miller
erights at google.com
Thu Feb 23 12:35:58 PST 2012
On Thu, Feb 23, 2012 at 12:18 PM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:
> Perhaps using indexOfIdentical from
> http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
>
+1. If they want the behavior that's broken on -0.0 and NaN in the
traditional way, I don't think that there's enough difference between saying
if (arr.contains(foo)) {
vs
if (arr.indexOf(foo) !== -1) {
to justify adding a new API, whether a new method or a new type. However,
because fixing indexOf is not on the table, and I'd hate to introduce a
parallel similar-but-different indexOfIdentical method as standard, if
we're going to add any contains method as standard, it should not be
similarly broken.
________________________________________
> From: es-discuss-bounces at mozilla.org [es-discuss-bounces at mozilla.org] on
> behalf of Erik Arvidsson [erik.arvidsson at gmail.com]
> Sent: Thursday, February 23, 2012 15:15
> To: es-discuss at mozilla.org
> Subject: Array.prototype.contains
>
> DOM4 added a new interface called DOMStringList for the sole reason
> that Array does not have contains. Before this the return type was an
> Array of Strings so we could use indexOf, map, forEach etc. Now that
> it is using a non Array we lost all of that.
>
> Proposal: Add Array.prototype.contains, implemented as:
>
> Object.defineProperty(Array.prototype, 'contains', {
> value: function(value) {
> return this.indexOf(value) !== -1;
> },
> enumerable: false,
> configurable: true,
> writable: true
> }{);
>
>
> This is trivial enough to do in user code but since DOM4 depends on it
> we should just put it in the right place; In ES6.
>
> --
> erik
> _______________________________________________
> 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/20120223/2b5c798e/attachment.html>
More information about the es-discuss
mailing list