Point number 1: this is a stupid rule. There are two ways to name a function for a good reason, and ignoring the fact that to indicate one style is pretty dull, IMO.
Your problem, I think, is that your function was not defined at the time addEventHandler . This is because of something called a "climb." In this process, functions named with the syntax function myFunction() {} "rise" at the top of the function. Therefore, if you call them anywhere in the function, the function will work. For example, this will work:
el.addEventListener('click', foo); function foo() {}
However, the features named in your organization style do not come up. There is a variable declaration, but the value is not set until this line of code is reached. So this will not work:
el.addEventListener('click', foo); var foo = function() {};
The easiest way to get around this is to move all function definitions to the top of the field if there is no good reason to define them later. So this will work:
var foo = function() {}; el.addEventListener('click', foo);
source share