Skip to content

Instantly share code, notes, and snippets.

@joewalker
Created July 27, 2015 11:48
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 joewalker/8f0a929bef16aea32047 to your computer and use it in GitHub Desktop.
Save joewalker/8f0a929bef16aea32047 to your computer and use it in GitHub Desktop.
What happens if you nest toJSON functions?
var obj = {
foo: 'foo',
toJSON: function() {
return {
bar: 'bar',
toJSON: function() {
return {
baz: 'baz'
};
}
};
}
};
JSON.stringify(obj);
@joewalker
Copy link
Author

Spoiler: {"bar":"bar"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment