Moreover, #each (and most of enumerable methods) accepts "context"
object as a second argument - since this is such a common need.

SomeComplexDataStructure.DataPart.each( function(DataPart) {
  this.myRecursiveFunction(DataPart);
}, this );

It's also good to remember that using bind is a little slower than
storing context in a separate variable.

- kangax


On May 27, 2:44 pm, "Ryan Gahl" <[EMAIL PROTECTED]> wrote:
> :)
>
> Both are good patterns to know about (mine of course only works if you are
> using prototype while yours is good old javascript).
>
> On 5/27/08, Frederick Polgardy <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Buy him a beer instead; this solution is a lot better than mine in this
> > case.
>
> > On Tue, May 27, 2008 at 1:04 PM, Ryan Gahl <[EMAIL PROTECTED]> wrote:
>
> >> Another way to do this could be to just use proto's .bind(), assuming the
> >> "myRecursiveFunction" is only ever called as an instance method (vs. 
> >> calling
> >> it statically against the MyNS.Package's prototype)...
>
> >> So:
>
> >> SomeComplexDataStructure.DataPart.each( function(DataPart) {
> >> *this.myRecursiveFunction(DataPart);* // or whatever the args should be
> >> }.bind(this) );
>
> > --
> > Science answers questions; philosophy questions answers.
>
> --
> Ryan Gahl
> Manager, Senior Software Engineer
> Nth Penguin, LLChttp://www.nthpenguin.com
> --
> WebWidgetry.com / MashupStudio.com
> Future Home of the World's First Complete Web Platform
> --
> Inquire: 1-920-574-2218
> Blog:http://www.someElement.com
> LinkedIn Profile:http://www.linkedin.com/in/ryangahl
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to