Opened 12 years ago
Closed 12 years ago
#9316 closed feature (wontfix)
Make .delegate(null, 'type', fnHandler) behave like .bind('type', fnHandler)
Reported by: | maranomynet | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.7 |
Component: | event | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description (last modified by )
There are circumstances where it would be incredibly handy if jQuery.fn.delegate
would handle the special case of an empty/falsy selector parameter, and interpret it as a direct .bind()
request on the collection.
The current behavior in jQuery happens to be almost like that, except that when the collection object is missing a selector
property things start failing. I suspect there's some sort of a fallback on .live()
going on - and causing those unpredictable results.
Adding this as a feature shouldn't add too much bloat to the core library, and would IMHO adhere to the principle of least surprise.
Change History (13)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Status: | new → open |
comment:5 Changed 12 years ago by
-1, I'd prefer the other way around, and make .on() an alias for bind.
comment:6 Changed 12 years ago by
I'd like to explain the events that lead to my filing this ticket.
I have a plugin that binds events to a container element. The plugin also accepts a target
subselector option to limit the events to just certain elements.
My initial assumption was that passing an empty/null selector to .delegate
would act just like .bind
. So I tried it:
this.delegate( options.targets||'', 'click', handlerFunc );
...and everything worked perfectly just as I had assumed.
Then after a few weeks of happy use things started to randomly fail, it seemed. After a long and confusing debugging session I finally figured out that the cause was a seemingly aribtary lack of .selector
property on the collection.
The following is the code I ended up reverting back to:
if ( options.targets ) { this.delegate( options.targets, 'click', handlerFunc ); } else { this.bind( 'click', handlerFunc ); }
...and it seems a lot less elegant than the original version.
comment:7 Changed 12 years ago by
Description: | modified (diff) |
---|
I think this ticket should be closed in favor of #9393
comment:8 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, Ehh, why not just do that logic in your code?
comment:9 Changed 12 years ago by
The point is: The feature is already there. Everything seems to work beautifully - but then it breaks down under specific rare (and seemingly random) circumstances.
comment:11 Changed 12 years ago by
Description: | modified (diff) |
---|
-1, There are a number of cases in jQuery where dynamically building parameters to send to jQuery functions works ALMOST all the time, but due to some kind of data exception, undefined ends up getting passed and jQuery behaves unexpectedly. (undefined as context or the second argument to attr, for instance). Historically, we have not special cased these situations, and I don't think we should start now, especially given the .on enhancement that will handle this problem generically.
comment:13 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Keywords: | 1.7-discuss removed |
Milestone: | 1.next → 1.7 |
Priority: | undecided → low |
Resolution: | → wontfix |
Status: | open → closed |
This will be dealt with in #9393
This will fall under the pending 1.7 event DRY out proposal