Ticket #11934 (closed feature: wontfix)
Enhancement: allow ":once" on event names to indicate one() variant event binding
| Reported by: | getify | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | event | Version: | 1.7.2 |
| Keywords: | 1.9-discuss | Cc: | |
| Blocking: | Blocked by: |
Description
I am a big fan of the "one()" functionality. But I have a suggestion for a small piece of sugar to extend it:
Allow me to put ":once" on the end of any event name in any of the event binding APIs (bind, on, etc) which tells jQuery to use the "one()" variant for the binding of that particular event. For example:
$("a").bind("click:once",handle)
// vs. $("a").one("click",handle)
$("#foobar").on("mousedown:once mouseup","a",handle)
// vs. $("#foobar").one("mousedown","a",handle).on("mouseup","a",handle)
Change History
comment:1 Changed 11 months ago by dmethvin
- Status changed from new to open
- Component changed from unfiled to event
- Priority changed from undecided to low
- Milestone changed from None to 1.9
- Keywords 1.9-discuss added
- Type changed from enhancement to feature
comment:2 Changed 11 months ago by getify
FWIW, Mootools has a whole system of "Event Pseudos", including ":once"...
http://mootools.net/docs/more/Class/Events.Pseudos
Perhaps that's a pattern jQuery could consider for this.
comment:3 Changed 8 months ago by dmethvin
-1, This doesn't fit in at all with our string event syntax, and the colon char is used by frameworks.
comment:7 Changed 7 months ago by rwaldron
-1, No new custom selectors. No new event system complexities
comment:10 Changed 7 months ago by mikesherov
- Status changed from open to closed
- Resolution set to wontfix
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

There might be a case to be made for a CSS-selectors-like handling of the event string, but I'm not a fan of making an exception for ":once" alone. Also, many external users are now using the ":" character in their custom event strings so we would need to be very careful about creating compatibility issues. I'll mark it for 1.9 discussion.