Peter Michaux wrote:
> On 12/16/06, RobG <[EMAIL PROTECTED]> wrote:
>
> > > <pseudocode>
> > >
> > >   function attachMyObserver() {
> > >     function handler(){}
> > >     attach("myDiv", 'click', handler);
> > >   }
> > >
> > > </pseudocode>
> > >
> > > So it isn't an anonymous function but a named inner function. Now how
> > > would i detach just that handler? There isn't a reference to it
> > > outside the outer function.
> >
> > The reference is 'handler', you pass it in the call, it creates a
> > closure back to the outer function.
>
> So what is the syntax to do this?
>
> <pseudocode>
>
>   function attachMyObserver() {
>      function handler(){}
>      attach("myDiv", 'click', handler);
>    }
>
>   attachMyObserver();
>   detach('myDiv', 'click', handler);
>
> </pseudocode>


  var fn = (function(){
    function handler(){...}
    return {
      addHandler : function(el, eType){
       attach(el, eType, handler);
      },
      delHandler : function(el, eType){
       detach(el, eType, handler);
      }
    };
  })();

  fn.addHandler(...);
  fn.delHandler(...);

QED :-)

There are other (probably less efficient) methods but the principle is
the same.

-- 
Rob


--~--~---------~--~----~------------~-------~--~----~
 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