Bug Tracker

Ticket #9779 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Allow non-null|undefined evaluation of data property values

Reported by: utvara@… Owned by: rwaldron
Priority: blocker Milestone: 1.6.3
Component: data Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to event

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 3 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 3 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 3 years ago by rwaldron

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 3 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 3 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 3 years ago by rwaldron

  • Status changed from closed to reopened
  • Resolution invalid deleted

comment:10 Changed 3 years ago by rwaldron

#9918 is a duplicate of this ticket.

comment:11 Changed 3 years ago by rwaldron

#9917 is a duplicate of this ticket.

comment:12 Changed 3 years ago by rwaldron

  • Owner set to rwaldron
  • Priority changed from low to high
  • Status changed from reopened to assigned
  • Component changed from event to data

comment:13 Changed 3 years ago by rwaldron

  • Priority changed from high to blocker
  • Summary changed from API inconsistency when calling named object event handler, data is not passed to Allow non-null|undefined evaluation of data property values

comment:12 Changed 3 years ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Merge pull request #432 from rwldrn/9794

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

Changeset: 59936dc04d4dd2731874fecd6237383a0e41ddd5

comment:13 Changed 3 years ago by dmethvin

  • Milestone changed from 1.next to 1.6.3
Note: See TracTickets for help on using tickets.