Simple data emitter and subscriber from scratch in Javascript

Have to ever used a reactive setup in JS?Lets try to make it from scratch

So if you have used any reactive stuff in JS, it mainly contains two methods, one for emitting the data and one for listen the changes by subscribing to it.

Lets say we have a class CustomRxm, So it should have two methods emit and subscribe

We are going to use these methods like:

Lets code these methods:-

See we are getting a callback function as an argument in subscribe method.The trick is to store this as class variable and call this in emit method with new data as argument.
(Since this is a simple example this will only work with one subscriber)

In action:-

--

--