Why do you have to pass the event object as a parameter?

后端 未结 5 1456
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 10:37

I\'m learning how to manipulate events in JavaScript and I\'m wondering \"why do you have to pass the event object as a parameter (argument) into a function when using event

5条回答
  •  执念已碎
    2020-12-28 10:56

    You aren't passing an event into the function, you are naming the first parameter passed to your function event.

    The browser is the one that is going to call your function and it passes an event object when it calls your function. You can choose not to name that parameter function(){} but the browser is still going to pass the event object in, you can use it or not use it as you see fit.

提交回复
热议问题