By design, the observer pattern stores only one instance of the observer. Then the event handler calls this observer several times with other instances of the event object that contains the event parameters: which element triggered the event, what is the context, etc.
Thus, the handler is not duplicated, but is mentioned in each "listener store".
Note:
Kemal Dag also notes that anonymous functions, by definition, offer less performance than a named function, I do not know if this is true, but if so, the difference is not significant. Especially for a language like JavaScript, which uses anonymous functions so widely, it cannot afford to affect performance.
source share