Closure when using event handler


/ Published in: JavaScript
Save to your folder(s)

requires mootools


Copy this code and paste it in your HTML
  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

You need to login to post a comment.