I have made 3 functions on calling the windowScroll function. Why does it not work with the extra parenthesis, but works when inside its own function or without parenthesis?
var windowScroll = function() {
var doesNotRun = function() {
console.log('does not run');
};
var doesRun = function() {
console.log('does run');
};
window.onscroll = doesNotRun();
window.onscroll = doesRun;
window.addEventListener('scroll', function(){
doesRun();
});
};
windowScroll();
Here is a link on codepen: http://codepen.io/marcoangelo/pen/KWdWem
Any help to understand why Javascript does this would be great.