>From your private reply to me (you probably wanted to reply to the
group address, not mine):

> I'm guessing I can chain as many different methods for 'this' as I
> want in that line, as long as I end it with the bind(this), yeah?

I'm not sure I know what you mean by that.  But for example, if you
wanted to do three things with the element -- say, enabling it,
setting its opacity to 50%, and apply the 'blarg' style to it -- you
could do this:

onSuccess: (function() {
    this.enable();
    this.setOpacity(0.5);
    this.setStyle('blarg');
}).bind(this)

That defines a new anonymous function, then binds 'this' to it (so
that 'this' within the function will be the reference you expect).
Note that parens around the function definition, you need them.  Also
note that we're only *defining* the function, not calling it; it'll
get called by the success event.
--
T.J. Crowder
tj / crowder software / com

On Apr 3, 11:41 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> > Is there something clever I can do with bindings or something here?
>
> Yup! :-)
>
> * * * *
>     onSuccess: this.enable.bind(this);
> * * * *
>
> Details:http://www.prototypejs.org/api/function/bindhttp://www.prototypejs.org/api/function/bindAsEventListener
>
> More on this issue in general (disclosure - it's my own 
> blog):http://blog.niftysnippets.org/2008/04/you-must-remember-this.html
>
> Hope this helps,
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Apr 3, 11:04 am, Jonny Nott <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I'm trying to use Ajax.updater within a function which I'll be calling
> > on a variety of different elements. The element is 'this' within the
> > function, so I can specify the first argument of Ajax.updater using
> > this.identify() like this:
>
> > new Ajax.Updater(this.identify(), locationUrl, {
> >         method: 'get',
> >         onSuccess: function () {
> >                 $('myElement').enable();
> >         }
>
> > });
>
> > ...but then how do I refer to 'this' within my onSuccess callback
> > function? In the above I'm having to specify it explicitly using $
> > ('myElement'), but that's not going to be any use if I want to call my
> > function on *any* element:
>
> > onSuccess: function () {
> >         this.enable(); // doesn't work, because 'this' isn't 'myElement'
> > inside callback func
>
> > }
>
> > Is there something clever I can do with bindings or something here?
>
> > Jonny
--~--~---------~--~----~------------~-------~--~----~
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