Loading ...
Sorry, an error occurred while loading the content.

Re: forEach break - couple of options

Expand Messages
  • berg.matt
    Returning a TAFFY object makes sense, but maybe something like TAFFY.exit or TAFFY.quit, since break is a reserved word. If you return something like a string
    Message 1 of 2 , Jun 20, 2008
    View Source
    • 0 Attachment
      Returning a TAFFY object makes sense, but maybe something like
      TAFFY.exit or TAFFY.quit, since break is a reserved word.

      If you return something like a string or false, couldn't it be
      possible that is the value you want to return?

      Matt

      --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
      >
      > Matt requested a break option for forEach loops. I thought it was
      > worth putting it on here in case anyone else had a comment. I can see
      > a couple of different options to make this work.
      >
      > Option 1 - you break a forEachby returning text from your function:
      > myStuff.forEach(function(r,n){
      > return "break";
      > })
      >
      > Option 2 - you break a forEach by returning a special function:
      > myStuff.forEach(function(r,n){
      > return TAFFY.break;
      > })
      >
      > Option 3 - you break a forEach returning false from your function:
      > myStuff.forEach(function(r,n){
      > return false;
      > })
      >
      > Right now if you return anything in a forEach it assumes that is a
      > record and overwrites it in the collection via an update. We could
      > make it so you could return any text and it would break, just the word
      > break, false, or a special function that or Object. What makes the
      > most sense and would cause the least confusion?
      >
      > Can any one else thing of a case where returning a special function or
      > even a custom function from forEach would be useful beyond breaking?
      > Is there any reason to return TAFFY.remove to remove the record you
      > just looped over (for example)?
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.