Skip to content

Instantly share code, notes, and snippets.

@ik9999
Last active November 16, 2015 16:54
Show Gist options
  • Save ik9999/2d236d9a07ea033d4dac to your computer and use it in GitHub Desktop.
Save ik9999/2d236d9a07ea033d4dac to your computer and use it in GitHub Desktop.
javascript - json.stringify with circular references handling and functions.
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