Skip to main content

Bug Tracker

Side navigation

#13627 closed bug (wontfix)

Opened March 19, 2013 06:22PM UTC

Closed March 19, 2013 06:57PM UTC

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

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

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
jQuery(obj).trigger('focus');

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/

Attachments (0)
Change History (3)

Changed March 19, 2013 06:36PM UTC by dmethvin comment:1

owner: → sahab.yazdani@gmail.com
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?

Changed March 19, 2013 06:53PM UTC by sahab.yazdani@gmail.com comment:2

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.

Changed March 19, 2013 06:57PM UTC by dmethvin comment:3

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.

https://github.com/jquery/api.jquery.com/issues/125