I still dislike forEach() same as some(); since the semantics are just
more complicated. break doesn work (ok return true), but named break
is gone, continue is now called return, and named continue is gone,
and you cannot return from the parent function, which often I do to
shortcut. You lose so much and gain so little.  this pointer is not
the objects method you are in, but the array/object, etc. I'm with
Marcel most of my objects just don't come with non-owned clutter,
for(key in obj) just keeps the semantics better and will do fine, and
if they do,
  if (!obj.hasOwnProperty(key)) continue;
isn't that hard. And before I use that forEach() and a callback id
just write this if performance is a consideration:
  for (var i = 0, iK = Object.keys(obj), iZ = iK.length; i < iZ; i++) {
Its still a one-liner (ok two if you need to get key/val), and once
you get used to it, it just like a phrase hardly using brain-cells to
go through

But in the end its just taste/style and there is not "right" answer.

On Mon, Feb 13, 2012 at 7:11 PM, Tim Caswell <[email protected]> wrote:
> On Mon, Feb 13, 2012 at 11:21 AM, Axel Kittenberger <[email protected]> wrote:
>> some() is only for Arrays tough.
>
> Same with forEach.  I had forgotten about Array.prototype.some().
>
> If you want the short-circuit of some, use my code from above, but
> call it "some" to avoid confusion.
>
>> On Mon, Feb 13, 2012 at 5:47 PM, substack <[email protected]> wrote:
>>> On Feb 13, 7:01 am, Axel Kittenberger <[email protected]> wrote:
>>>> Why they didn't make the standard forEach in that returning false
>>>> terminates the loop is beyond me...
>>>
>>> You can just abuse the short-circuiting of [].some:
>>>
>>>> [ 1, 2, 3, 4, 5, 6, 7 ].some(function (x) { console.log(x); if (x > 4) 
>>>> return true })
>>> 1
>>> 2
>>> 3
>>> 4
>>> 5
>>>
>>> Instead of `return false`, it's `return true`.
>>>
>>> --
>>> Job Board: http://jobs.nodejs.org/
>>> Posting guidelines: 
>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines: 
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to