Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
Created November 15, 2012 19:01
Show Gist options
  • Save maxfridbe/4080497 to your computer and use it in GitHub Desktop.
Save maxfridbe/4080497 to your computer and use it in GitHub Desktop.
Console and Pub Sub
(function(NS, $, undefined) {
//idea gleaned from https://gist.github.com/661855
var o = $({});
NS.Events = {};
NS.Events.subscribe = function () {
console.log('Subscribing to ' + arguments[0]);
o.on.apply(o, arguments);
};
NS.Events.unsubscribe = function () {
console.log('UnSubscribing from ' + arguments[0]);
o.off.apply(o, arguments);
};
NS.Events.publish = function () {
console.log('Raising ' + arguments[0]);
o.trigger.apply(o, arguments);
};
})(window.NS = window.NS || {}, jQuery);
//https://github.com/andyet/ConsoleDummy.js
(function (con) {
// the dummy function
function dummy() { };
// console methods that may exist
for (var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(','), func; func = methods.pop(); ) {
con[func] = con[func] || dummy;
}
} (window.console = window.console || {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment