Posted By

ichnoweb on 09/04/10


Tagged

closure mootools


Versions (?)

Closure when using event handler


 / Published in: JavaScript
 

requires mootools

  1. /* Function in class */
  2. prepareLabels: function(dataProperty,defaultEvent){
  3. var i = 0;
  4. $each(stageLabels,function(listElement){
  5. listElement.setProperty(dataProperty,i);
  6. listElement.addEvent(defaultEvent,function(e){
  7. /* changeImage => other function in class */
  8. this.changeImage(e.target);
  9. }.bind(this)); /* bind -> sets function-context */
  10. i++;
  11. },this);
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: BarrydeRond on October 10, 2010

It quite depends on what type of application you are building, but instead of attaching many events to many objects, use event delegation.

You need to login to post a comment.