I realize I may get laughed out of the gym for this question, given how long 
I've used Mootools now, but...

For nearly every Mootools class I've ever written, I cannot seem to get away 
from needing to do this inside the class methods:

var that = this;

...where "this" refers to the class object.


Here's an example:

var Widget = new Class({

options: { optionvalue: 'hello' },

initialize: function (options) {
this.setOptions (options);

},
 widgetaction: function () {
var ev;
var that = this;
$('widgetlink').addEvent('click', function(e) {
ev = new Event(e).stop();
this.setStyles({'color': 'red'}); //change the color of 'widgetlink'
that.options.optionvalue = 'world'; 
});
}
});
Widget.implement(new Options, new Events);


I (mostly) understand the "bind" feature, but I don't think I can use it in 
my example above.  If I bind "widgetaction()" with the Widget class, then 
I'm not sure I'd have any way to change the "widgetlink" element inside the 
function called with the onClick event.

Does this question make sense?  What almost certainly obvious and stupid 
thing am I missing? 

Thanks (and ducking) in advance.

Reply via email to