Skip to content

Instantly share code, notes, and snippets.

@ptsurbeleu
Created November 2, 2015 19:20
Show Gist options
  • Save ptsurbeleu/f5e9e5594db698f31301 to your computer and use it in GitHub Desktop.
Save ptsurbeleu/f5e9e5594db698f31301 to your computer and use it in GitHub Desktop.
Adhoc debug description for a closure object in JavaScript
// Builds human-readable representation of the specified object for debugging purposes.
function debugDescription(object: any, category: string): string {
var tuples = [];
for (var property in object) {
if (object.hasOwnProperty(property)) {
if (typeof object[property] === "object") {
tuples.push("'" + property + "': " + debugDescription(object[property], ""));
} else {
tuples.push("'" + property + "': '" + object[property] + "'");
}
}
}
var description = "{ " + tuples.join(", ") + " }";
if (category !== "") {
description = "\r\n>>>> " + category + " <<<< ---> " + description + "\r\n";
}
return description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment