If you can't derive your parameters from the event.target DOM node, then yes 
you do have distinct functions for each link. However you can do this with 
closures. E.g.

function addClickH (node, i){
 node.addEventListener('click', function(event){myHandler(event, i)}, 
false);
}
for (var i=0; i < links.length; i++){
  addClickH(links[i], i)
}

Note that the following code will not set up the closures correctly:

for (var i=0; i < links.length; i++){
 links[i].addEventListener('click', function(e){myHandler(e, i)}, false);
}

Every event handler would be closed over the final value of 'i';

'Let' is supposed to create scope, so I think the following would give the 
proper closures:

for (var i=0; i < links.length; i++){
 let j = i;
 links[i].addEventListener('click', function(e){myHandle(e, j)}, false);
}



-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to