jQuery pub sub API implementation
(function ($) {
var o = $( {} ); // to return an instance of jquery that is to pass an empty object literal to jQuery to get a new
$.each({
trigger : 'publish',
on : 'subscribe',
off : 'unsubscribe'
}, function(key, val) {
jQuery[val] = function() {
o[key].apply(o, arguments);
};
});
})(jQuery);
// example usage
$.getJSON(url, function(data) {
$.publish('twitter/results', data);
});
// ...
$.subscribe('twitter/results', function(e, results) {
console.log(results);
});