Skip to content

Instantly share code, notes, and snippets.

@sivagao
sivagao / minimal_pubsub.js
Created April 2, 2013 10:02
minimal pubsub js
var pubsub = function(l, u, r, i) { // cool! 闭包并且初始化vars
return function(n, f) {
r = l[n] = l[n] || [], i = -1;
if (f && f.call) r.push(f);
else while (r[++i]) r[i].apply(u, arguments);
}
}({});
// subscribe to event
pubsub("eat_cookie", function() {