Side navigation
#9779 closed bug (fixed)
Opened July 07, 2011 09:27PM UTC
Closed August 04, 2011 09:55PM UTC
Last modified March 09, 2012 03:15AM UTC
Allow non-null|undefined evaluation of data property values
Reported by: | utvara@gmail.com | Owned by: | rwaldron |
---|---|---|---|
Priority: | blocker | Milestone: | 1.6.3 |
Component: | data | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When object has named event handler (joe: function ...) and event with type joe is triggerd on that object with additional data, that data isn't passed to the handler.
Example:
Blame: line 2888 (jQuery 1.6.1)
Bug is still there in 1.6.2
Attachments (0)
Change History (13)
Changed July 07, 2011 11:54PM UTC by comment:1
component: | unfiled → event |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Changed July 08, 2011 12:05AM UTC by comment:2
From jQuery's viewpoint that is an "inline" handler (not a jQuery event attached by a jQuery method) and shouldn't be passed anything but the event object. If you had a jQuery event attached to the object it would be passed the data.
At the moment this is undefined behavior, I'm not a fan of formalizing the use of inline handlers for plain objects. I'd be happier with checking for it being a DOM element nodeType==1 and only firing inline handlers for that.
Changed July 08, 2011 07:37AM UTC by comment:3
It was my mistake that I misunderstood that this was expected behavior :(
I used this as a reference:
It was unintentional - way back in the day - but we've come to embrace it. Expect those aforementioned methods (bind / unbind and data) to continue to work on plain JavaScript objects.
Problem is that the named method gets called twice if I am to bind to it rather than use closure.
Changed July 08, 2011 03:03PM UTC by comment:4
bind/unbind/trigger will definitely work with plain objects as my example shows above. The example you've given here: http://jsfiddle.net/2BSBe/1/ has the exact same behaviour all the way back to jQuery 1.2.6
Additionally, I tried your original code approach going back to jQuery 1.2.6 and every version since....
- jQuery 1.2.6 http://jsfiddle.net/rwaldron/zV39Y/
- jQuery 1.3.2 http://jsfiddle.net/rwaldron/aR3wb/2/
- jQuery 1.4.4 http://jsfiddle.net/rwaldron/aR3wb/3/
- jQuery 1.5.2 http://jsfiddle.net/rwaldron/aR3wb/4/
- jQuery 1.6.1 http://jsfiddle.net/rwaldron/aR3wb/5/
- jQuery Edge http://jsfiddle.net/rwaldron/aR3wb/6/
Sorry, but your example has never worked as you claim it should
Changed July 08, 2011 06:28PM UTC by comment:5
@rwaldron, right but we do support bind/trigger on plain JS objects. The undocumented side-effect is that $(obj).trigger("foo")
attempts to call obj.foo()
(regardless of whether it's even callable, because isFunction
won't work on some IE event handlers so we just have to go for it). Seems like checking for .nodeType==1
and not calling inline handlers might be a solution.
Problem is that the named method gets called twice if I am to bind to it rather than use closure.
Is there a reason to name the method and the event the same?
Changed July 08, 2011 09:11PM UTC by comment:6
@dmethvin I am using bind/trigger on plain JS objects a lot, mainly because I was inspired by YUI 3 custom events and stumbled upon the same behavior in jQuery, there are even examples of emulating the event bubbling trough the side effect.
As for the reason of naming the method and event the same name, again I must say I got to this behavior by stubbing, I was doing the proper bind/trigger and I noticed that the handler was called twice (lazy naming scheme) so I decided to roll with it until I found that method called by name isn't getting the event object nor the data.
I assume that the call was added to normalize some weird browser incompatibility, nevertheless I find that even in that case not passing event obj and data is API inconsistency. I might be wrong but I just thought it was wort pointing out.
Thank you for your time.
Changed July 12, 2011 07:09PM UTC by comment:7
resolution: | invalid |
---|---|
status: | closed → reopened |
Changed July 27, 2011 02:35PM UTC by comment:10
component: | event → data |
---|---|
owner: | → rwaldron |
priority: | low → high |
status: | reopened → assigned |
Changed July 27, 2011 02:37PM UTC by comment:11
priority: | high → blocker |
---|---|
summary: | API inconsistency when calling named object event handler, data is not passed → Allow non-null|undefined evaluation of data property values |
Changed August 04, 2011 09:55PM UTC by comment:12
Changed August 26, 2011 02:25AM UTC by comment:13
milestone: | 1.next → 1.6.3 |
---|
It's not a bug if your trying to do something that is not intended, tested or documented
http://jsfiddle.net/rwaldron/Mphcw/