Thanks for the quick reply. Just for clarification, if you have a
moment, could you perhaps explain why you would choose to iterate over
the elements rather than use a proxy variable? In my example, I'm
assuming that the iteration is implied, so it essentially does the
same thing as what you wrote, but it seems like it saves a line of
code. If the event were 'mouseover' rather than 'click' and you need
to have something similar for 'mouseout', you could save two lines. Do
you feel like it's more readable to explicitly iterate? I'm not too
familiar on conventions, etc, so I'm genuinely curious. Thanks again.
On Sep 17, 3:16 pm, nutron <[EMAIL PROTECTED]> wrote:
> In this particular instance, I'd iterate over the elements instead:
>
> $$(someClass).each(function(el) {
> el.addEvent('click', function(){
> el.addClass('someOtherClass');
> this.someFunction();
> }.bind(this));
>
> }, this);
>
> It's not bad form to make a reference to this into another variable name (as
> you have in your example) but I find it's rarely needed. In all the code
> I've written for the Clientside libraries, I can't think of an instance
> where I've had to do it. If so, it's only once or twice.
>
>
>
> VirtuosiMedia wrote:
>
> > Is there a better way to do have multiple 'this' references inside an
> > addEvent function? Right now I'm using a variable called thisProxy to
> > refer the global this and the this inside the function will refer to
> > that instance. I don't want to use bind because I need them both. Is
> > there a more elegant method?
>
> > Here's an example:
>
> > var thisProxy = this;
>
> > $$(someClass).addEvent('click', function(){
> > this.addClass('someOtherClass');
> > thisProxy.someFunction();
> > });
>
> -----
> The MooTools Tutorial: http://www.mootorial.comwww.mootorial.com
> CNET Clientside: http://clientside.cnet.comclientside.cnet.com
> --
> View this message in
> context:http://n2.nabble.com/Multiple-this-references-inside-the-addEvent-fun...
> Sent from the MooTools Users mailing list archive at Nabble.com.