Array.prototype.find
What would be the use case for this that isn't covered with Function#bind() or arrow functions?
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
>
>
> _______________________________________________
> 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/20130606/1e71f148/attachment-0001.html>I guess just consistency with other Array#forEach/map/every,etc,etc methods plus you don't need to create N bound functions or N arrow functions per each Array#find call ... or not?
I guess just consistency with other Array#forEach/map/every,etc,etc methods
plus you don't need to create N bound functions or N arrow functions per
each Array#find call ... or not?
On Thu, Jun 6, 2013 at 1:20 PM, 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
>>
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130606/fca2075d/attachment.html>On Thu, Jun 6, 2013 at 4:43 PM, Andrea Giammarchi < andrea.giammarchi at gmail.com> wrote:
I guess just consistency with other Array#forEach/map/every,etc,etc methods plus you don't need to create N bound functions or N arrow functions per each Array#find call ... or not?
None of those have a "default return value", so what are you referring to?
On Thu, Jun 6, 2013 at 4:43 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> I guess just consistency with other Array#forEach/map/every,etc,etc
> methods plus you don't need to create N bound functions or N arrow
> functions per each Array#find call ... or not?
>
None of those have a "default return value", so what are you referring to?
Rick
>
>
> On Thu, Jun 6, 2013 at 1:20 PM, 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
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>>
>
> _______________________________________________
> 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/20130606/4d108085/attachment-0001.html>the fact reduce/Right a part all methods accept a thisValue ... I am happy with current method though, still not sure if thisValue will be commonly needed or not.
the fact reduce/Right a part all methods accept a thisValue ... I am happy
with current method though, still not sure if thisValue will be commonly
needed or not.
On Thu, Jun 6, 2013 at 3:44 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
>
>
>
> On Thu, Jun 6, 2013 at 4:43 PM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
>> I guess just consistency with other Array#forEach/map/every,etc,etc
>> methods plus you don't need to create N bound functions or N arrow
>> functions per each Array#find call ... or not?
>>
>
>
> None of those have a "default return value", so what are you referring to?
>
> Rick
>
>
>>
>>
>> On Thu, Jun 6, 2013 at 1:20 PM, 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
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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/20130606/449b9cfa/attachment-0001.html>On Thu, Jun 6, 2013 at 6:56 PM, Andrea Giammarchi < andrea.giammarchi at gmail.com> wrote:
the fact reduce/Right a part all methods accept a thisValue ... I am happy with current method though, still not sure if thisValue will be commonly needed or not.
Seems irrelevant to the request for a "default return value"
On Thu, Jun 6, 2013 at 6:56 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> the fact reduce/Right a part all methods accept a thisValue ... I am happy
> with current method though, still not sure if thisValue will be commonly
> needed or not.
>
Seems irrelevant to the request for a "default return value"
Rick
>
>
> On Thu, Jun 6, 2013 at 3:44 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>>
>>
>>
>> On Thu, Jun 6, 2013 at 4:43 PM, Andrea Giammarchi <
>> andrea.giammarchi at gmail.com> wrote:
>>
>>> I guess just consistency with other Array#forEach/map/every,etc,etc
>>> methods plus you don't need to create N bound functions or N arrow
>>> functions per each Array#find call ... or not?
>>>
>>
>>
>> None of those have a "default return value", so what are you referring to?
>>
>> Rick
>>
>>
>>>
>>>
>>> On Thu, Jun 6, 2013 at 1:20 PM, 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
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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/20130606/09f33811/attachment-0001.html>Note: the proposed new parameter is returnValue, not thisArg (which has already been decided on).
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/52889bef/attachment-0001.html>Oops, my bad, sorry about that.
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>yep, I followed Jussi ... it's his fault :P
sorry I misunderstood too
yep, I followed Jussi ... it's his fault :P
sorry I misunderstood too
On Fri, Jun 7, 2013 at 7:03 AM, Jussi Kalliokoski <
jussi.kalliokoski at gmail.com> wrote:
> 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
>>
>>
> _______________________________________________
> 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/20130607/8095c94e/attachment-0001.html>
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; }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/20130528/67d6c695/attachment.html>