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.com www.mootorial.com 
CNET Clientside:  http://clientside.cnet.com clientside.cnet.com 
-- 
View this message in context: 
http://n2.nabble.com/Multiple-this-references-inside-the-addEvent-function-tp1096709p1096750.html
Sent from the MooTools Users mailing list archive at Nabble.com.

Reply via email to