I am interested in finding out what this actually does? if (result = !!(iterator || Prototype.K)(value, index)) I seen this function in the Prototype library and haven''t been able to find any documentation to gain insight into what the line above does. any: function(iterator) { var result = false; this.each(function(value, index) { if (result = !!(iterator || Prototype.K)(value, index)) throw $break; }); return result; }, More specifically it is the ... !!(iterator || Prototype.K)(value, index) ... piece of code that confuses me. -NSHB -- Nathaniel Steven Henry Brown Open Source Insight - http://nshb.net Open Source Development - http://inimit.com Open Source Training - http://osevents.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
It looks like it''s going to call the iterator function that''s passed in or Prototype.K if no iterator was passed in. In either case it passes ''value'' and ''index'' to the function. I''m guessing that the !! is going to work to convert the return value of that function call to a boolean, which is then assigned to result. On 9/22/06, Nathaniel Brown <nshb-wgYSSEAWXinQT0dZR+AlfA@public.gmane.org> wrote:> > > I am interested in finding out what this actually does? > > if (result = !!(iterator || Prototype.K)(value, index)) > > I seen this function in the Prototype library and haven''t been able to > find any documentation to gain insight into what the line above does. > > any: function(iterator) { > var result = false; > this.each(function(value, index) { > if (result = !!(iterator || Prototype.K)(value, index)) > throw $break; > }); > return result; > }, > > More specifically it is the ... !!(iterator || Prototype.K)(value, > index) ... piece of code that confuses me. > > -NSHB > > > -- > Nathaniel Steven Henry Brown > > Open Source Insight - http://nshb.net > Open Source Development - http://inimit.com > Open Source Training - http://osevents.com > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Prototype.K is just an empty function. So if iterator is not defined it will just use an empty function instead. The !!() forces the returned value of the function to be a boolean. Hope that breif description helps. Brandon On 9/22/06, Nathaniel Brown <nshb-wgYSSEAWXinQT0dZR+AlfA@public.gmane.org> wrote:> > I am interested in finding out what this actually does? > > if (result = !!(iterator || Prototype.K)(value, index)) > > I seen this function in the Prototype library and haven''t been able to > find any documentation to gain insight into what the line above does. > > any: function(iterator) { > var result = false; > this.each(function(value, index) { > if (result = !!(iterator || Prototype.K)(value, index)) > throw $break; > }); > return result; > }, > > More specifically it is the ... !!(iterator || Prototype.K)(value, > index) ... piece of code that confuses me. > > -NSHB > > > -- > Nathaniel Steven Henry Brown > > Open Source Insight - http://nshb.net > Open Source Development - http://inimit.com > Open Source Training - http://osevents.com > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Just as an additional precision, Prototype.K is *not* empty, it''s the identity (Kernel) function: it basically returns its first argument, untouched. Not to be mistaken with Prototype.EmptyFunction :-) Brandon Aaron a écrit :> Prototype.K is just an empty function. So if iterator is not defined > it will just use an empty function instead. The !!() forces the > returned value of the function to be a boolean.Indeed, the !! trick (double-logical-negation) forces any value to be converted to its boolean equivalent :-) -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---