JSFiddle - React, Tailwind, and code Playground
by joplomacedo
JavaScript
var evt = {
_cbs: {},
subscribe: function (name, cb) {
this._cbs[name] = this._cbs[name] || [];
this._cbs[name].push(cb);
},
emit: function (name) {
var args = Array.prototype.slice.call(arguments, 1);
this._cbs[name] && this._cbs[name].forEach(function (cb) {
cb.apply(null, args);
});
}
};
evt.subscribe('lol', ( a, b) => {
console.log(a, b)
})
evt.emit('lol', 4, 50)