You have a self-initialization function:
(function() { alert("a") })();
as you can warn this code about warnings "a" .
In your function, you then initialize fnName . What you need to do:
window.addEventListener('scroll', function( event ) { fnName(event, some, param ); }, false);
When the scroll event fnName , you then initialize fnName with your custom arguments.
And as indicated, if you want to remove the handler again, you will need a named function:
function myFn( event ) { fnName(event, some, param ); } window.addEventListener('scroll', myFn, false);
source share