1. So there is no longer $continue and I have to use return
2. I understand the behavior of return because it is a function given to each()
but It's not the same behavior like in other programming language:
In Java:
public Object method(){
for (Iterator it = collect.iterator; it.hasNext(); ){
Object obj = it.next();
if (...){ continue; }
if (...){ continue; }
if (...){ continue; }
return obj;
}
}
In prototype I have to do:
function(){
var good;
$H(collect).each(function(entry,idx){
if (...){ return; /* throw $continue; */}
if (...){ return; }
if (...){ return; }
good = entry.value;
throw $break;
}
return good;
}
That's more complicated. I hoped to return directly entry.value;
Regards
On 2/1/07, Marius Feraru <[EMAIL PROTECTED]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Jean-Philippe Encausse wrote:
> > A little question about each() function:
> > function test() {
> > $H(hashtable).each(function(entry,idx){ /* code */ });
> > }
> >
> > In my /*code*/ I can do
> > - throw $continue
> > - throw $break
> >
> > But can I do a return xxx ?
> Yes, it will have the same effect as (the already obsolete)
> "throw $continue".
>
> > It seems the loop didn't ends ? Is it normal ?
> OFC it's normal. Remember that "your code is outside of the loop scope: the
> looping code happens behind the scene". Yes, I was quoting the docs:
> http://prototypejs.org/api/enumerable/each
>
> Jean-Philippe, should I suppose you were trying to use "each -> return"
> hoping for a "filter"? That's plain wrong, you should use "grep", "find" or
> "findAll" for such things. For example, to filter out "false" values you
> could use:
> $H({ a:0, b:1, c:0, d:3 }).findAll(function(x){ return x.value })
> // returns: [["b", 1], ["d", 3]]
>
>
> BTW, folks, we need a documentation update, telling people there is no
> "throw $continue" in Enumerables from starters, in order to avoid any
> confusion when they will update to a newer version which won't support that
> for good (yes, Sam already dropped it in SVN).
>
> - --
> Marius Feraru
> -----BEGIN PGP SIGNATURE-----
>
> iD8DBQFFwdPPtZHp/AYZiNkRAhziAKCiCXt7ThBdL6TM8kduCmVh6l2fdwCgyfuT
> mYMLYeq2KWfaXbMh6pNjQ0Y=
> =0ILK
> -----END PGP SIGNATURE-----
>
> >
>
--
Jean-Philippe Encausse - R&D Jalios SA
Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com
GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net
Mob: +33 6 82 12 56 99 Jalios: +33 1 39 23 92 83 Tel: +33 1 39 18 90 15
Do it Once, Use it Twice ~ Do it Twice, Make It Once
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---