#9779 closed bug (fixed)
Allow non-null|undefined evaluation of data property values
Reported by: | Owned by: | Rick Waldron | |
---|---|---|---|
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: http://jsfiddle.net/pLuUx/
Blame: line 2888 (jQuery 1.6.1)
Bug is still there in 1.6.2
Change History (13)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 12 years ago by
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.
comment:3 Changed 12 years ago by
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.
comment:4 Changed 12 years ago by
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
comment:5 Changed 12 years ago by
@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?
comment:6 Changed 12 years ago by
@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.
comment:7 Changed 12 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:12 Changed 12 years ago by
Component: | event → data |
---|---|
Owner: | set to Rick Waldron |
Priority: | low → high |
Status: | reopened → assigned |
comment:13 Changed 12 years ago by
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 |
comment:12 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Merge pull request #432 from rwldrn/9794
Correct non-null|undefined evaluation of data property values. Fixes #9779
Changeset: 59936dc04d4dd2731874fecd6237383a0e41ddd5
comment:13 Changed 12 years ago by
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/