I've been really stuck on something and I'm coming to you as a last resort. I have a JavaScript file (parent.js) that is loading another .js file (child.js). The parent.js file has an event subscription:
Class.prototype.subscribe('someEvent', someEventHandler)
Very similar to what Facebook does:
FB.Event.subscribe('auth.authResponseChange', auth_response_change_callback);
FB.Event.subscribe('auth.statusChange', auth_status_change_callback);
I'm trying to understand how child.js can dispatch (or broadcast) someEvent
so that someEventHandler
gets fired.
It seems like everything I see tells about how to add the listener, but nothing about how to dispatch an event to handle the method attached to the listener.
References: API-docs https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.3
Someone with similar resolved issue, but I'm not using Facebook SDK, just using the example to make my objective clearer:
FB.Event.subscribe not firing for certain events
Event dispatching in general: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events