Hacker News new | ask | show | jobs
by damncabbage 4907 days ago
I see this problem all the time in my own code and that of my colleagues: callbacks that have been registered either more or less times than the author of the code expected. Usually more times.

I've yet to run into this problem before, and I'm an even split between JS / Ruby these days. Are you building on top of any particular libraries or frameworks? Could you give some examples of where you've encountered this?

2 comments

I've encountered it once with a form, although it was a while ago and if I saw the code again I might be able to identify what was wrong. In that case it was probably a poor choice of element to attach to that caused the callback to be fired independently multiple times on one click, and stopping the bubbling had no effect.

The other time was in a Rails app, where a script was added to a partial for a layout, and then added again later on (by a different developer) to the layout itself. That caused a particularly nasty bug since it used 'toggle', and thus the second callback negated the first.

i've also run into this, usually through double event binding