Created
March 16, 2015 17:20
-
-
Save bgadrian/2cf08c5c3b89eec4d38c to your computer and use it in GitHub Desktop.
JS log to console multiple parameters,objects,functions etc
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
/** Console logs all the parameters received. Can handle objects, functions, doms etc | |
usage : log('myObj = ',obj,'other x = ',x); | |
*/ | |
function log() | |
{ | |
buffer = ''; | |
for (var i = 0; i < arguments.length; i++) | |
{ | |
if (typeof(arguments[i]) == 'object' | |
|| typeof(arguments[i]) == 'function') | |
{ | |
if (buffer.length) | |
console.log(buffer); | |
buffer = ''; | |
console.log(arguments[i]); | |
//if you are NOT using CHROME (where objects can be viewed) use | |
// console.log(JSON.stringify(arguments[i])); | |
} | |
else | |
{ | |
buffer += '[' + arguments[i] + ']'; | |
} | |
} | |
if (buffer.length) console.log(buffer); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment