When setting up event callbacks using modern standards, the client automatically passes a reference to the event object into each event callback function. It will always be the first argument.
You don't need to do anything to make that happen. All you need to do is capture the reference and you can do that with any named argument you like. Since you are the recipient of the argument, the name you choose doesn't have to match up with anything. You can call it anything (that is a valid identifier that is).
Now, your example only works because in the Global scope of a web page the window
object exposes a single event
object and that is what a(event)
is accessing.:
<input onChange="a(event)"/>
<script>
function a(event) {
alert(event.target.value);
}
</script>
But, this is not the modern way that events should be set up. Inline HTML event attributes (onclick
, onchange
, etc.) should not be used (here's why).
The modern approach is as follows and note that the registration of the event callback function (a
) doesn't indicate anything about an event, yet the actual function is able to get the information it needs just by expecting an argument.
document.querySelector("input").addEventListener("change", a);
function a(anyNameIsGoodHere) {
alert(anyNameIsGoodHere.target.value);
}
<div>Type anything into the text field and then hit TAB</div>
<input>