On Feb 6, 2008 10:53 PM, Nycto <[EMAIL PROTECTED]> wrote:
>
> Is there a way to invoke an anonymous function and have the function
> itself returned?
>
> What I am trying to do is attach an observer to an element, and at the
> same time run the observer so that the initial state is set. My
> javascript looks like this:
>
> function toggleDetails () {
> $$('.moreDetails').invoke( $F('showDetails') == 'y' ? 'hide' :
> 'show' );
> }
> $('showDetails').observe( 'change', toggleDetails );
> toggleDetails();
function toggleDetails() {
// your code
return arguments.callee;
}
$("showDetails").observe("change", toggleDetails());
That should work
-Nicolas
> Bascially, it adds a control to show the "moreDetails" sections of a
> form when a toggle is set to "yes".
>
> But I feel like this could be done in less code... maybe using an
> anonymous function that is invoked as it is attached as an observer.
> Something like this:
>
> $('showDetails').observe( 'change', function () {
> $$('.moreDetails').invoke( $F('showDetails') == 'y' ? 'hide' :
> 'show' );
> }.invokeAndReturn() );
>
> Where invokeAndReturn() is a method that calls "this", discards the
> results, and then just returns "this".
>
> Am I over complicating this?
>
> Thanks for any help you can offer
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---