Skip to content

Instantly share code, notes, and snippets.

@erikpukinskis
Last active March 29, 2017 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikpukinskis/b5293e145828a1b2f71c75fb2955501c to your computer and use it in GitHub Desktop.
Save erikpukinskis/b5293e145828a1b2f71c75fb2955501c to your computer and use it in GitHub Desktop.
global.wtf = function wtf(label, whatnot) {
if (!whatnot){
whatnot = label
label = undefined
}
if (typeof whatnot == "function") {
var out = whatnot.toString()
} else if (typeof whatnot == "object") {
if (Array.isArray(whatnot)) {
var out = JSON.stringify(whatnot)
} else {
var out = "[ object "+whatnot.constructor.name+" with keys "+Object.keys(whatnot).join(", ")+" ]"
}
} else {
var out = JSON.stringify(whatnot)
}
if (label) {
console.log(label, out)
} else {
console.log(out)
}
}
var references = []
function ignoreCircularReferences(key, value) {
if (typeof value === 'object' && value !== null) {
var isCached = references.indexOf(value) !== -1
if (isCached) { return "<<< CIRCLE >>>" }
references.push(value)
}
return value
}
// var a = {}
// a.a = a
// JSON.stringify(a, ignoreCircularReferences)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment