Modify ↓
Ticket #1140 (closed bug: fixed)
bind() incorrectly passes fn as data
| Reported by: | arrix | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.1.3 |
| Component: | event | Version: | 1.1.2 |
| Keywords: | event bind data | Cc: | |
| Blocking: | Blocked by: |
Description
If you call $(selector).bind(type, fn), fn will be used as data. So event handlers checking for event.data presence will not works as expected. e.g.
function handler(event) {
if (event.data) {
//gets executed even if no data was specified for bind()
} else {
//no data provided
}
}
In event.js,
bind: function( type, data, fn ) {
return this.each(function(){
jQuery.event.add( this, type, fn || data, data );
});
},
The call to jQuery.event.add always passes the 3rd parameter.
Attachments
Change History
comment:1 Changed 6 years ago by arrix
patch
Index: E:/zm/jquery/jquery/src/event/event.js
===================================================================
--- E:/zm/jquery/jquery/src/event/event.js (revision 1771)
+++ E:/zm/jquery/jquery/src/event/event.js (working copy)
@@ -274,7 +274,7 @@
*/
bind: function( type, data, fn ) {
return this.each(function(){
- jQuery.event.add( this, type, fn || data, data );
+ jQuery.event.add( this, type, fn || data, fn && data );
});
},
@@ -309,7 +309,7 @@
jQuery.event.add( this, type, function(event) {
jQuery(this).unbind(event);
return (fn || data).apply( this, arguments);
- }, data);
+ }, fn && data);
});
},
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.


to reproduce the bug