Last active
November 16, 2015 16:54
-
-
Save ik9999/2d236d9a07ea033d4dac to your computer and use it in GitHub Desktop.
javascript - json.stringify with circular references handling and functions.
This file contains hidden or 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
var cache = []; | |
var str = JSON.stringify({a: infer.registerFunction}, function(key, value) { | |
if (typeof value === 'object' && value !== null) { | |
if (cache.indexOf(value) !== -1) { | |
return; | |
} | |
cache.push(value); | |
} | |
if (typeof value === 'function') { | |
return '' + value; | |
} | |
return value; | |
}) | |
cache = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment