Skip to main content

Bug Tracker

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:

http://jsfiddle.net/pLuUx/

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 rwaldron comment:1

component: unfiledevent
priority: undecidedlow
resolution: → invalid
status: newclosed

It's not a bug if your trying to do something that is not intended, tested or documented

http://jsfiddle.net/rwaldron/Mphcw/

Changed July 08, 2011 12:05AM UTC by dmethvin 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 utvara@gmail.com 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.

http://jsfiddle.net/2BSBe/1/

Changed July 08, 2011 03:03PM UTC by rwaldron 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....

Sorry, but your example has never worked as you claim it should

Changed July 08, 2011 06:28PM UTC by dmethvin 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 utvara@gmail.com 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 rwaldron comment:7

resolution: invalid
status: closedreopened

Changed July 27, 2011 02:32PM UTC by rwaldron comment:8

#9918 is a duplicate of this ticket.

Changed July 27, 2011 02:32PM UTC by rwaldron comment:9

#9917 is a duplicate of this ticket.

Changed July 27, 2011 02:35PM UTC by rwaldron comment:10

component: eventdata
owner: → rwaldron
priority: lowhigh
status: reopenedassigned

Changed July 27, 2011 02:37PM UTC by rwaldron comment:11

priority: highblocker
summary: API inconsistency when calling named object event handler, data is not passedAllow non-null|undefined evaluation of data property values

Changed August 04, 2011 09:55PM UTC by Dave Methvin comment:12

resolution: → fixed
status: assignedclosed

Merge pull request #432 from rwldrn/9794

Correct non-null|undefined evaluation of data property values. Fixes #9779

Changeset: 59936dc04d4dd2731874fecd6237383a0e41ddd5

Changed August 26, 2011 02:25AM UTC by dmethvin comment:13

milestone: 1.next1.6.3