The problem with implementing an event system is to properly disable listeners. Changing the list of listeners when calling callbacks can lead to unexpected behavior.
, , 2 , x. x , index 0 index 1. index 0 . index 1. Loop index 1. , .
, , . , . .
d3 listeners.
listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
, , . event . defensive reference , , ( ) listeners, , listeners .