Array.prototype.find

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Fri Jun 7 07:03:10 PDT 2013


Oops, my bad,  sorry about that.
On Jun 7, 2013 3:37 AM, "Axel Rauschmayer" <axel at rauschma.de> wrote:

> Note: the proposed new parameter is `returnValue`, not `thisArg` (which
> has already been decided on).
>
> On Jun 6, 2013, at 22:20 , Jussi Kalliokoski <jussi.kalliokoski at gmail.com>
> wrote:
>
> What would be the use case for this that isn't covered with
> Function#bind() or arrow functions?
>
> Cheers,
> Jussi
>
> On Wed, May 29, 2013 at 5:50 AM, Axel Rauschmayer <axel at rauschma.de>wrote:
>
>> It might make sense to add a third argument to that method, so that it
>> works roughly like this:
>>
>>     Array.prototype.find = function (predicate, returnValue = undefined,
>> thisArg = undefined) {
>>         var arr = Object(this);
>>         if (typeof predicate !== 'function') {
>>             throw new TypeError();
>>         }
>>         for(var i=0; i < arr.length; i++) {
>>             if (i in arr) {  // skip holes
>>                 var elem = arr[i];
>>                 if (predicate.call(thisValue, elem, i, arr)) {
>>                     return elem;
>>                 }
>>             }
>>         }
>>         return returnValue;
>>     }
>>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130607/bac0446d/attachment-0001.html>


More information about the es-discuss mailing list