-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Chaining .on() broken for null handlers in jQuery 2.2.0 (inconsistency with 1.12.0) #2812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A callback can't be |
It's weird, though, we brought the check for EDIT: Ah, I misread the report. It's not throwing but returns |
Correct. The callback doesn't necessarily have to be null but if its not a function, window is returned |
After looking more at the source code, it seems like this reverted commit is the culprit (the on function was broken out so 'this' has a different meaning now): 3cc496c |
A function or Thanks for the report! |
Good point, that's it! Note that we've removed this check on I'd fix it on the Thoughts, @jquery/core? |
The code had been refactored as a non-method function to hide the private If we have a unit test in there it seems like we're saying we want a non- |
The issue I encountered is somewhat similar to this here, as it relates to the event refactoring. If you think this warrants it's own feature/bug report that is fine with me. Here's what happened: After upgrading to jQuery 2.2.0 hoverintent for ui-tabs threw an error e.preventDefault() is not a function in the user defined event handler callback function, even though a quick test showed that typeof e.preventDefault returned 'function'. The code I was using is an updated version of this http://stackoverflow.com/questions/15346939/adding-hoverintent-to-jquery-ui-tabs. The most important change from that code is the line jQuery.event.handle.apply( that, args ); jQuery.event.dispatch.apply( that, args ); And i had changed from bind()/unbind() to on()/off(). I reverted to bind()/unbind() during bug triaging, but that made no difference to the error. After unsuccessfully trying to pin point the problem I found this jquery-ui example Using that code my ui-tabs with hoverintent and hoverintent in general works again, although I did made some refactoring (using on()/off() instead of bind()/unbind(), and giving the events a namespace). Since this issue shows up when using special event handlers, it might have an effect on other plug-ins, I hope this report helps to save people from spending a lot of time to fix similar issues. Probably needs no fixing in jQuery, altough the fixed version is less performant than using jQuery.event.dispatch directly as it doesn't have to do all the work that is done in the trigger function (which seems to be a special event in itself) |
Yeah, I agree that its probably not critical enough for a quick 2.2.1 release. It could potentially break plugins that chain on like the one above where not all options are always set though so it might be worth fixing for compatibility. Though plugins shouldn't be doing that anyways. |
I've added a milestone. |
Yeah, I will do that |
Fixed by #2825 |
The current 2.2.0 breaks jQuery Mobile selectMenu with data-native-menu="false". see http://plnkr.co/edit/dant044hERO4zpEJgB8S |
@vankampenp If it's related to this issue, it has already been fixed and will be released in 2.2.1. |
Not work fine, see jquery-archive/jquery-mobile#8381 (comment) |
It looks like a bug was introduced in jquery 2.2.0 with the 'on' function.
If you have code that registers a bunch of handlers in a chain and one of the callbacks is null, the on function will return the window object when the callback is null which causes the chaining to fail. This works with jquery 2.1.4. After a little investigation, it looks like the 'on' method was refactored to be global within jquery's scope and returns this (which used to be the jquery object but now is window).
//example from jquery impromptu plugin
$('.selector').on("keydown",keyDownEventHandler)
.on('impromptu:loaded', opts.loaded)
.on('impromptu:close', opts.close)
.on('impromptu:statechanging', opts.statechanging)
.on('impromptu:statechanged', opts.statechanged);
The text was updated successfully, but these errors were encountered: