I need to attach a function to the resize event, but it doesn't work if the function has parameters, it works if I execute the function inside an anonymous function, but then I'm not able to remove the listener as theirs no reference to it.
Here is my code:
addEvent(window, 'resize', self.center(e) ); // Doesn't work
addEvent(window, 'resize', function() { // Does work but can't remove the listener
self.center(e);
});
'addEvent' is just a simple cross-browser event listener function. I don't get any errors, the event just doesn't fire.
No jQuery answers please.
Edit:
addEvent Function:
function addEvent(elem, event, fn) {
if(elem.addEventListener) {
elem.addEventListener(event, fn);
} else {
elem.attachEvent('on' + event, fn);
}
}