addEventListener
does not return a value, so handler
is undefined
and the call to removeEventListener
will fail.
Use a named function expression instead:
// give the function a name vvvvvvv
e.target.addEventListener('mouseout', function handler(d) {
// ...
this.removeEventListener('mouseout', handler, false); // use name
}, false); // <- don't forget `false` here, just in case
The name of the function is only accessible inside the function itself.