Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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.

Change History (2)

comment:1 Changed 9 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);
 		});
 	},
 

comment:2 Changed 9 years ago by brandon

  • Resolution set to fixed
  • Status changed from new to closed

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

Note: See TracTickets for help on using tickets.