I need covert this code from mootools 1.2 to 1.3
var SomeClass = new Class({
initialize: function (els) {
for (var i = 0; i < els.length; i++) {
els[i].addEvent('click',
this.alert.bindWithEvent(this, [i, els[i].get('text')])
);
}
},
alert: function (event, index, text) {
alert(
index + ' -> ' + text + ' | ' +
'x:' + event.page.x + ', y:' + event.page.y
);
}
});
Here is the working version (1.2) http://jsfiddle.net/9Pn99/
Here is my version for 1.3 http //jsfiddle.net/9Pn99/1/
EDIT:
I figured out how to do it, with a closure. http://jsfiddle.net/9Pn99/4/
for (var i = 0; i < els.length; i++) {
(function (j) {
els[i].addEvent('click',
function (e) {
this.alert(e, j);
}.bind(this)
);
}.pass([i], this))();
}
Is there a better solution?
EDIT2: I found another easy way:
els.each(function (el, i) {
els[i].addEvent('click',
function (e) {
this.alert(e, i);
}.bind(this)
);
}, this);
Looks like I'm talking alone.
els[i].addEvent
should just beel.addEvent
, otherwise, 100% on the money - i did not see your edit before i set out to do my answer :( deleting shortly.