Ticket #6993 (closed enhancement: fixed)
.bind() and .one() don't allow a function as data
| Reported by: | davidflanagan | Owned by: | john |
|---|---|---|---|
| Priority: | low | Milestone: | 1.6 |
| Component: | event | Version: | 1.4.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
The .bind() and .one() methods take two or three arguments, and have the signatures:
bind(type, data, handler) bind(type, handler)
Currently, jQuery 1.4.2 distinguishes these cases with this code:
if ( jQuery.isFunction( data ) ) {
fn = data; data = undefined;
}
This means that if you pass a function as the data argument, it will be treated as the handler argument and the handler will be ignored.
I propose that you change the code to instead test like this:
if (arguments.length === 2) {
fn = data; data = undefined;
}
Change History
comment:2 Changed 3 years ago by snover
- Priority set to low
- Status changed from new to open
- Version changed from 1.4.2 to 1.4.3
- Type changed from bug to enhancement
- Milestone changed from 1.4.3 to 1.next
comment:3 Changed 3 years ago by snover
- Milestone changed from 1.4.4 to 1.5
Retarget all enhancements/features to next major version.
comment:4 Changed 2 years ago by john
- Owner set to john
- Status changed from open to assigned
- Milestone set to 1.6
comment:5 Changed 2 years ago by John Resig
- Status changed from assigned to closed
- Resolution set to fixed
Allow function to be passed in as a data object to bind and one. Fixes #6993.
Changeset: 6e3b596514d20124260bc4b3febd8dc105420626
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

See line 2371 in jquery-1.4.2.js for the code referred to above. (It doesn't look right the way I pasted it into the ticket.)