I have a simple event listener:
function listen(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);
else if (elem.attachEvent) { // IE DOM
var r = elem.attachEvent("on"+evnt, func);
return r;
}
return false;
}
I want to set listeners with a parameter. (the parameter is not set by the event, it is part of specific listener.
What I do and seems to work is:
function setlistener (param){
listen ('custom event', document,
function (e){
run_func_with_param(param);
}
);
}
But I dont understand if its correct because param is not supposed to be defined when the event is fired.
My question is - is it the right way to have run_func_with_param called, each time with the params that was set for it in setlistener? In other words, is param remembered and will be set to the right values when run_func_with_param will be called as result of an event? (there will be multiple listeners with different params for the same event).
Notes: No jQuery/other libraries please. I'm using a custom event in this case.