Difference between calling function and referencing function?

前端 未结 3 1800
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 05:57

Look at the following code:

window.onload = someFunction;

Many times I see the use of this kind of code and even I use the same. But, there

3条回答
  •  不思量自难忘°
    2020-12-07 06:14

    In this case, you are registering a callback function for the window onload event. To do so, you give a reference to the function, you don't execute the function (unless, of course, executing the function returns another function which is used as the callback handler). The function you specify will be executed when the onload event occurs, that is, when the page finishes loading.

提交回复
热议问题