Skip to content

Instantly share code, notes, and snippets.

@zachstronaut
Created September 10, 2011 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zachstronaut/1208947 to your computer and use it in GitHub Desktop.
Save zachstronaut/1208947 to your computer and use it in GitHub Desktop.
Update NimbleKit's NKLog with proper variable interrogation
//
// 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;
}
@zachstronaut
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment