Create a gist now

Instantly share code, notes, and snippets.

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

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