[Proposal] Array.prototype.includes should evaluate object.toString and/or object.valueOf when determining a match
Peter Jaszkowiak
p.jaszkow at gmail.com
Wed Jun 20 18:29:36 UTC 2018
If you want to check properties or methods of an array of objects, you can
use `Array.prototype.some`.
On Wed, Jun 20, 2018, 12:27 Mike Simon <nixkuroi at gmail.com> wrote:
> [Proposal] Array.prototype.includes should evaluate object.toString
> and/or object.valueOf when determining a match
>
> The problem:
>
> If I have a list of objects that contain a toString() prototype that
> returns a value from the object, Array.prototype.includes does not return
> true if the value/string returned from the object is a match for the
> parameter value.
>
> Test code:
>
> var thingy = function(name) {this.name=name;};
> thingy.prototype.valueOf = function(){return this.name};
> thingy.prototype.toString = function(){return this.name};
> var items = [new thingy('abc'),new thingy('def')];
> var inc = items.includes('abc');
> alert(items[0]); // alerts abc
> alert(inc); // returns false
>
> While it’s possible to create this as a list of strings using map, this
> would seem to conserve memory, as well as reduce the complexity of the code
> to perform this operation.
>
> Link:
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
> _______________________________________________
> 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/20180620/aab534f0/attachment.html>
More information about the es-discuss
mailing list