Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13627 closed bug (wontfix)

Focus event bound on a plain JS object does not work correctly.

Reported by: sahab.yazdani@… Owned by: sahab.yazdani@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


We use jQuery to bind/trigger events on plain JS objects like so. One of our objects has a method on it called "focus", and we also define a method on it called "focus", like so:

var obj = { focus: function() {} };
jQuery(obj).bind('focus', fn);

// later on

In jQuery 1.8.3, both the focus member and the focus event would get invoked. In jQuery 1.9.1, only the focus member gets invoked. This is definitely an edge case, but it represents a diffence of behaviour between jQuery 1.8.3 and jQuery 1.9.1. The reason comes down to a special event defined for IE's sake that tries to call the focus method of the DOM element. Ideally (for me anyways), the special event would make sure the object is a DOM node before invoking thereby creating a distinction between events and methods, but I understand that it may not be practical to actually implement that way for such an edge use case. Just want to log this change in behaviour somewhere in case this trips up any other people.

JSFiddle: http://jsfiddle.net/hqJ5A/

Change History (3)

comment:1 Changed 7 years ago by dmethvin

Owner: set to sahab.yazdani@…
Status: newpending

In general you should not use DOM event names if you don't want DOM semantics. Otherwise we'd need to check for special cases all over the place. Is there a problem doing that in your app?

comment:2 Changed 7 years ago by sahab.yazdani@…

Status: pendingnew

Well we've created a UI widget toolkit and used jQuery for the eventing system (among other things), so event names such as "focus", "blur", etc. are perfectly valid names for events on non-DOM objects in my case.

I guess my real concern is that notes like the one @dmethvin put in this issue are not easily found (or are they? I honestly have not read the docs in a while, but there doesn't seem to be a mention of anything similar in the trigger docs..)

Again, I don't necessarily expect a fix, and don't really consider this a bug either TBH. My use case is rather on the edge, but it is something that tripped me up in the migration to 1.9.1.

comment:3 Changed 7 years ago by dmethvin

Resolution: wontfix
Status: newclosed

Triggering events on plain objects isn't a common thing. There's an open api docs ticket and I've just added a ref to here.


Note: See TracTickets for help on using tickets.