Array.prototype.contains

Rick Waldron waldron.rick at gmail.com
Fri Feb 24 11:09:16 PST 2012


On Thu, Feb 23, 2012 at 3:15 PM, Erik Arvidsson <erik.arvidsson at gmail.com>wrote:

> 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.
>

Wouldn't the return type (or [[Class]]) still be restricted from using
"Array"?

>From 8.6.2

The value of the [[Class]] internal property is defined by this
specification for every kind of built-in object. The value of the [[Class]]
internal property of a host object may be any String value except one of
"Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON",
"Math", "Number", "Object", "RegExp", and "String".


So it can't be an "Array" by name, right?


(I'm not trying to be contrary, just looking for clarity :D )


>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120224/091b0b1b/attachment.html>


More information about the es-discuss mailing list