Cross-environment event emitter solution for JavaScript