Can someone explain me what does this line of code means:
function(e) { e = e || event; e.returnValue = false; return false; }
Why is the parameter named e
?
If I change it to 'myparam' will it work?
What does e = e
mean?
Where is the variable event
( after ||
) declared ?
What is e.returnValue?
The e parameter of the function is an optional parameter of the input event handler which equals to a JavaScript Event object that contains information regarding what action or event just happened.
Event handlers can be used to handle and verify user input, user actions, and browser actions: Things that should be done every time a page loads. Things that should be done when the page is closed. Action that should be performed when a user clicks a button.
This is all basic event management, although it is missing e.preventDefault()
...
To break it down, when an event handler is fired:
window.event
(which is accessed here with just event
, which is risky since that relies on there being no local variable with that name)Next, e = e || event;
is a standard way of saying "if the parameter was not passed, default it to whatever's after the ||
". In this case, if the event parameter is not passed, then it looks for the global variable.
e.returnValue
is one of three ways to stop an event from causing its default action. The other two are e.preventDefault && e.preventDefault()
(which is conspicuously absent from the code you posted), and return false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With