This seems to be a very popular question though i didn’t seem to find any pertinat answers.
I attach an event listen like :
window.addEventListener('scroll', fnName, false);
The problem is that fnName expect several parameters, so i then triedl
window.addEventListener('scroll', (function( e ){
return fnName(e, some, param )
}()), false)
but then window.removeEventListener do not work anymore so i tried:
window.removeEventListener('scroll', (function( e ){
return fnName(e, some, param )
}()), false)
Every time you declare an anonymous function, it creates a new function instance. If you want to remove an existing function, you need to retain a copy of the function instance.
I should also note that using
calls
fnNameimmediately withundefinedas the first parameter. I doubt that’s your intention.