Created
September 10, 2011 23:30
-
-
Save zachstronaut/1208947 to your computer and use it in GitHub Desktop.
Update NimbleKit's NKLog with proper variable interrogation
This file contains 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
// | |
// https://gist.github.com/1208947 | |
// Include this JS right after NKit.js in your HTML files. | |
// Now NKLog() will show you the contents of arrays and objects! | |
// | |
var NKLog1 = NKLog; | |
var NKLog = function (arg) { | |
NKLog1('\n' + NKInterogate(arg)); | |
} | |
function NKInterogate(arg) { | |
var output; | |
if (typeof arg === 'object' && arg.length) { | |
output = '[\n'; | |
for (var i = 0; i < arg.length; i++) { | |
output += '\t' + NKInterogate(arg[i]).toString().split('\n').join('\n\t') + ',\n'; | |
} | |
output += ']'; | |
} else if (typeof arg === 'object') { | |
output = '{\n'; | |
for (k in arg) { | |
output += '\t' + k + ': ' + NKInterogate(arg[k]).toString().split('\n').join('\n\t') + ',\n'; | |
} | |
output += '}'; | |
} else if (typeof arg === 'string') { | |
output = '"' + arg + '"'; | |
} else { | |
output = arg; | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSON.stringify() unfortunately doesn't quite give the output the way I want it, and also doesn't report functions correctly.
NimbleKit's NKLog() does not function like console.log() in Firebug or Webkit Inspector... it would just output [Object object] which wasn't very useful.