Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#9779 closed bug (fixed)

Allow non-null|undefined evaluation of data property values

Reported by: utvara@… 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 6 years ago by Rick Waldron

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/

comment:2 Changed 6 years ago by dmethvin

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 6 years ago by utvara@…

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/

comment:4 Changed 6 years ago by Rick Waldron

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

comment:5 Changed 6 years ago by dmethvin

@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 6 years ago by utvara@…

@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 6 years ago by Rick Waldron

Resolution: invalid
Status: closedreopened

comment:10 Changed 6 years ago by Rick Waldron

#9918 is a duplicate of this ticket.

comment:11 Changed 6 years ago by Rick Waldron

#9917 is a duplicate of this ticket.

comment:12 Changed 6 years ago by Rick Waldron

Component: eventdata
Owner: set to Rick Waldron
Priority: lowhigh
Status: reopenedassigned

comment:13 Changed 6 years ago by Rick Waldron

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

comment:12 Changed 6 years ago by Dave Methvin

Resolution: fixed
Status: assignedclosed

Merge pull request #432 from rwldrn/9794

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

Changeset: 59936dc04d4dd2731874fecd6237383a0e41ddd5

comment:13 Changed 6 years ago by dmethvin

Milestone: 1.next1.6.3
Note: See TracTickets for help on using tickets.