Bug Tracker

Ticket #1140 (closed bug: fixed)

Opened 8 years ago

Last modified 8 years ago

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

test.htm Download (569 bytes) - added by arrix 8 years ago.
to reproduce the bug

Change History

Changed 8 years ago by arrix

to reproduce the bug

comment:1 Changed 8 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 8 years ago by brandon

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

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

Note: See TracTickets for help on using tickets.