Sitemap

Events Emitter in JavaScript

Dec 14, 2023

--

Press enter or click to view image in full size

If you worked with JavaScript in the browser, you know how much of the interaction of the user is handled through events: mouse clicks, keyboard button presses, reacting to mouse movements, and so on.

Get Brightefoo’s stories in your inbox

Join Medium for free to get updates from this writer.

Using events is therefore a good practice and can be very useful.

I create a simple implementation of the event module. That implementation is ready for use on my npm through this link : https://www.npmjs.com/package/brightkyefoo-event-emitter

This implementation uses javascript proxies. You have with this api a bunch of three methods, emit, on and once respectively for fire an event, connect an event listener which will be triggered anytime the corresponding event will be fired and connect an event listener which will be triggered only once.

--

--