Skip to content

Instantly share code, notes, and snippets.

@aogilvie
Last active December 7, 2015 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aogilvie/d04a9d2478e10dcd4cee to your computer and use it in GitHub Desktop.
Save aogilvie/d04a9d2478e10dcd4cee to your computer and use it in GitHub Desktop.
Pretty console the scope of your console.info
(function() {
// Usage - attach scope to last argument for printing scope:
// console.info('whatever', this);
// console.info('whatever', { a: 'abc'}, ..., this);
if (window.console && console.info){
var old = console.info;
console.info = function() {
var len = arguments.length;
if (len -1 > 0 &&
Object.prototype.toString.call(arguments[len - 1]) === '[object Object]' &&
arguments[len - 1].constructor.name !== 'Object') {
Array.prototype.unshift.call(arguments, '[' + arguments[len - 1].constructor.name + ']');
Array.prototype.pop.call(arguments, len - 1);
}
old.apply(this, arguments);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment