Maybe because "some_el_2" is lower down in the DOM tree? I think at least the experiment should be run with reversed IDs.
Always return on events is faster, but why?
31–40 of 52 posts
Re: Always return on events is faster, but why?
#32Earlier quoted context omitted.
eulerphi: FYI you're hellbanned
Isn't the idea of hellbanning that people don't realize they are? Kinda defeats the purpose if you notify them of it. If HN wanted people to know they've been silenced, they would be given an error message. So, don't tell people. It's also spamming the comment with offtopic remarks.
Most people that are hellbanned on HN have not at all deserved it. Ignoring spambots, I've seen perhaps two users that got a hellban for consistently problematic posts rather than a single post annoying someone. And one of those has actual mental issues.
Re: Always return on events is faster, but why?
#33Doesn'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".
As many pointed out, I was wrong. An empty return doesn't equal a false return. Neither does jQuery interpret a return of undefined as a stopPropagation, as this fiddle shows: http://jsfiddle.net/6UGN8/
Re: Always return on events is faster, but why?
#34I posted it on the page as well: Doesn't just calling return from an event equate to returning boolean false, which means you are invoking the effects of preventDefault() and stopImmediatePropagation() thus explaining why with return it's faster as the event stops bubbling immediately?
https://github.com/jquery/jquery/blob/a5037cb9e3851b171b49f6...
So returning undefined does NOT stop propagation.
Re: Always return on events is faster, but why?
#35One of the most important things to remember while using jsPerf is that setup phase can and will be executed multiple times. As the result the list of listeners attached to the DOM node is growing and this in turn slows down the event dispatch.
"No return" case is run second so the list of listeners is already large and thus it is slower than "return case".
You should either unregister listeners in tear down phase or register them only once at global initialization time. Here is the fixed variant:
http://jsperf.com/always-return-on-jquery-events/28
[also from the JavaScript VM point of view function () { } and function () { return; } are completely the same]
Re: Always return on events is faster, but why?
#36Earlier quoted context omitted.
eulerphi: FYI you're hellbanned
Isn't the idea of hellbanning that people don't realize they are? Kinda defeats the purpose if you notify them of it. If HN wanted people to know they've been silenced, they would be given an error message. So, don't tell people. It's also spamming the comment with offtopic remarks.
Re: Always return on events is faster, but why?
#37Earlier quoted context omitted.
eulerphi: FYI you're hellbanned
Isn't the idea of hellbanning that people don't realize they are? Kinda defeats the purpose if you notify them of it. If HN wanted people to know they've been silenced, they would be given an error message. So, don't tell people. It's also spamming the comment with offtopic remarks.
And the answer to it being overused is for people to call it out whenever a user is trying to contribute but hellbanned, and we don't agree with the ban after taking a look at their comment history.
Re: Always return on events is faster, but why?
#38Answer is simple: you are adding more and more listeners as jsPerf runs your test case. One of the most important things to remember while using jsPerf is that setup phase can and will be executed multiple times. As the result the list of listeners attached to the DOM node is growing and this in turn slows down the event dispatch. "No return" case is run second so the list of listeners is already large and thus it is…
If the OP wanted to measure function with or without return , even without realizing how futile that is, they still should not include things like jQuery.
Re: Always return on events is faster, but why?
#39Earlier quoted context omitted.
return without return false is just like breaking out of a method i think.. The events would still bubble since false isn't returned
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. Both versions have the same return value as illustrated by this fiddle http://jsfiddle.net/QHxJ3/
Re: Always return on events is faster, but why?
#40Earlier quoted context omitted.
eulerphi: FYI you're hellbanned
Isn't the idea of hellbanning that people don't realize they are? Kinda defeats the purpose if you notify them of it. If HN wanted people to know they've been silenced, they would be given an error message. So, don't tell people. It's also spamming the comment with offtopic remarks.