#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: | |
Blocked by: | Blocking: |
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 (1)
Change History (3)
Changed 16 years ago by
comment:1 Changed 16 years ago by
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); }); },
comment:2 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
to reproduce the bug