This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
It seems to be a common pattern to have code like: element.addEventListener("click", function onClick(event) { element.removeEventListener("click", onClick); ... }); jQuery has method ".one()" to simplify this pattern. I think it would be great if DOM directly includes a method for this in EventTarget. Probably this method could be: void listenForNextEvent(DOMString type, EventListener? callback, optional boolean capture = false);
> Probably this method could be: > > void listenForNextEvent(DOMString type, EventListener? callback, optional > boolean capture = false); Or the existing method could be extended by a fourth parameter: void addEventListener(DOMString type, EventListener? callback, optional boolean capture = false, optional boolean once = false) Sebastian
I'm vote for this because do this a lot of time... and will be nice if this new stuff can remove anonymous callback too.
Closing this for now. If we do this we should have a new better event API in general, that addresses a number of concerns. https://gist.github.com/annevk/4475457 has a sketch of such a thing, if you're interested.
This is now https://github.com/whatwg/dom/pull/207. I found a way to do this now addEventListener() takes options. Would love your feedback.