Doesn't a return without argument return false and thus have the same effect as preventDefault()? That would explain the difference, since the events are not "bubbling up".
An empty return statement has the return value undefined which is falsy. As lukashed said jQuery most likely interprets this as false and stop propagation of the event, however using an empty function also has the return value undefined so both cases stops propagation.
> 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).
The two functions are different, but their return values are identical. The === is comparing the return values.
Consider this example:
function onePlusOne() { return 1 + 1; }
function two() { return 2; }
alert( onePlusOne === two ); // false, not the same function
alert( onePlusOne() === two() ); // true, same value