You can remove a listener with an anonymous function in the way you show. I suspect your problem is the location of the removeEventListener statement. Is it inside obj? The best location is in obj.func, assuming that this event is only needed once.

And as for mdc saying that the first way is wrong and the second one is correct, it's a bit misleading in that context. Wrongness there has nothing to do with memory issues, but with the fact that |this| is "wrong", which usually is not what is wanted.

It was more then misleading. The this object available within a method is set by the caller and is often not the object the method belongs to. Not really the wrong object just not the one you might think it should be. Every function is a method of an object even if the object is not stated, in which case it is a method of the current window object. Example: alert() and window.alert() are the same.

Calling addEventListener to an anonymous function creates a new listener each time. Calling removeEventListener to an anonymous function has no effect. An anonymous function creates a unique object each time is is called, it is not a reference to an existing object though it may call one. When adding an event listener in this manner be sure it is added only once, it is permanent (can not be removed) untill the object it was added to is destroyed.

(Technical detail) Someone said above, "Calling addEventListener to an anonymous function creates a new listener each time." If this was ever true, it is no longer true. The documentation says, "If multiple identical EventListeners are registered on the same EventTarget with the same parameters, the duplicate instances are discarded." So if addEventListener is called multiple times with the same callback function (anonymous or named), only the last call has an effect. Note: to call multiple times with the same anonymous function, save the function in a variable and use the variable. If you simply copy the anonymous function definition, a new function is created and referenced, and so a new listener is indeed added.