I understand how to trigger and listen for custom events. I can’t figure out how Bootstrap is listening to custom events without triggering them.
https://github.com/twitter/bootstrap/blob/master/js/bootstrap-scrollspy.js#L32
Nowhere in their code can I find where they are triggering that custom scroll event. I took a look at the jQuery on docs and couldn’t see if events are naturally namespaced somehow.
How does this work?
They’re listening to the scroll event which is a naturally occurring event. It’s not a custom event, they’ve just namespaced it. The reason for namespacing it is so you can remove all events by just removing the namespace from all events. Look at Using Namespaces in unbind.