Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created December 1, 2011 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Raynos/1412316 to your computer and use it in GitHub Desktop.
Save Raynos/1412316 to your computer and use it in GitHub Desktop.
pub sub
var pubsub = (function () {
return { pub: pub, sub: sub, evs: {} };
function pub(ev, data) {
pubsub.evs[ev] && pubsub.evs[ev].forEach(function (h) { h(data); });
}
function sub(ev, h) {
(pubsub.evs[ev] || (pubsub.evs[ev] = [])).push(h);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment