How to remove all events from the eventDispatcher?

I set events to some objects using addEventListener. Every time I do this, it seems the old events are preserved as well. But what I would like, is to cleanup events before setting new ones.

How can I do that? removeEventListener needs a function, but I declare the eventfunctions inline so I do not keep a pointer to them after adding.

I guess you need:

It’s best to post a comment at the PR and ask for merging.

Mayby I am doing this wrong, but as a test I’ve added the RemoveAllEventListeners to the EventDispatcher-prototype (in a bit of a hacky-way), but I think it removes too much.

First, I put this temporary hack in the top of my code, just to add the new function:
THREE.EventDispatcher.prototype.removeAllEventListeners= function () {
this._listeners = undefined;
}

Now, I have a TransformControl that I re-use over and over. But as soon as I fire removeAllEventListeners, it stops working entirely.

I think my best solution would be not to re-use the transformControl, but I wanted you to know that this seems to be a side effect.

That is strange. EventDispatcher manages listeners per object in the _listeners property. It’s not possible that the removal of all event listeners of one object affects another one.

Maybe I do not understand it quite right: what I meant is when I remove the events from the TransformControl, the same TransformControl-object looses its default events.

Oh okay. Yes, that’s right.