Skip to main content

Bug Tracker

Side navigation

#1140 closed bug (fixed)

Opened April 24, 2007 04:50AM UTC

Closed April 24, 2007 09:52PM UTC

Last modified June 21, 2007 04:53AM UTC

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)
  • test.htm (0.6 KB) - added by arrix April 24, 2007 04:51AM UTC.

    to reproduce the bug

Change History (2)

Changed April 24, 2007 04:58AM UTC by arrix comment:1

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);
 		});
 	},
 

Changed April 24, 2007 09:52PM UTC by brandon comment:2

resolution: → fixed
status: newclosed

Fixed in Rev. 1773 and I change the != handler back to != undefined in Rev. 1774 :/