Last active
March 29, 2017 20:24
-
-
Save erikpukinskis/b5293e145828a1b2f71c75fb2955501c to your computer and use it in GitHub Desktop.
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
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