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

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

Is there a difference between:

  1. window.onload = someFunction;

  2. window.onload = someFunction();

Th

5条回答
  •  粉色の甜心
    2020-12-18 15:44

    window.onload = someFunction; assigns a function to onload.

    window.onload = someFunction(); calls a function and assigns its return value to onload. (This is not desirable unless the return value of that function is another function).

    What if we Have to pass some parameter to the function

    Usually you define a new function which does nothing except call the original function with some arguments, then you assign the new function to the event handler.

提交回复
热议问题