JavaScript! [removed] = someFunction and [removed] = someFunction()

后端 未结 5 1609
逝去的感伤
逝去的感伤 2020-12-18 14:55

Is there a difference between:

  1. window.onload = someFunction;

  2. window.onload = someFunction();

Th

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 15:29

    Yes. If you put window.onload = someFunction() it is expected that the result of someFunction() is another function. This could be used for wrapping a function, or passing parameters. For instance:

    window.onload = myFunction(arg1, arg2)
    

    myFunction(arg1, arg2) would be expected to return some function incorporating these two variables.

提交回复
热议问题