it's easiest to just assign it to local variable:
var f = function () {
$$('.moreDetails').invoke( $F('showDetails') == 'y' ? 'hide' :
'show' );
};
f();
$('showDetails').observe( 'change', f );

if you're running that script within another function it won't be
leaked to the global scope so you should be all set.
I'd expect you're probably doing something along these lines:

$(window).observe('load', function(){
  var f = function () {
  $$('.moreDetails').invoke( $F('showDetails') == 'y' ? 'hide' :
'show' );
  };
  f();
  $('showDetails').observe( 'change', f );
});

On Feb 6, 7: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();
>
> 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?
>
> Th    anks 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to