> As lukashed said jQuery most likely interprets [undefined] as false and stop propagation of the event...
No, it doesn't. jQuery uses a strict test for false and does not stop propagation for other falsy return values from an event listener.
The documentation could be more clear on this point. All it says is: "Returning false from an event handler will automatically call event.stopPropagation() and event.preventDefault()."
Reading that code, it almost seems redundant at first to have a !== undefined check when the === false is already a strict comparison. But there is that assignment hidden inside the if expression. So the code is really the same as this more clearly written version:
if ( ret !== undefined ) {
event.result = ret;
if ( ret === false ) {
event.preventDefault();
event.stopPropagation();
}
}
This would also have the same effect:
if ( ret !== undefined ) {
event.result = ret;
}
if ( ret === false ) {
event.preventDefault();
event.stopPropagation();
}
These all do the same thing: set event.result only if ret is not undefined, and then call preventDefault and stopPropagation only if ret is false (and not just a falsy value).
No, it doesn't. jQuery uses a strict test for false and does not stop propagation for other falsy return values from an event listener.
The documentation could be more clear on this point. All it says is: "Returning false from an event handler will automatically call event.stopPropagation() and event.preventDefault()."
http://api.jquery.com/on/#event-handler
Here's the code that does this check:
https://github.com/jquery/jquery/blob/master/src/event.js#L3...Reading that code, it almost seems redundant at first to have a !== undefined check when the === false is already a strict comparison. But there is that assignment hidden inside the if expression. So the code is really the same as this more clearly written version:
This would also have the same effect: These all do the same thing: set event.result only if ret is not undefined, and then call preventDefault and stopPropagation only if ret is false (and not just a falsy value).