Last active
December 7, 2015 03:01
-
-
Save aogilvie/d04a9d2478e10dcd4cee to your computer and use it in GitHub Desktop.
Pretty console the scope of your console.info
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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