xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Object.stringify 循环引用 bug & TypeError: Converting circular structure to JSON

Object.stringify 循环引用 bug & TypeError: Converting circular structure to JSON

var obj = {
  a: "foo",
};
// undefined

obj;
//{a: "foo"}

obj.b = obj;
// {a: "foo", b: {…}}

JSON.stringify(obj);

/*
VM205:1 Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'b' closes the circle
    at JSON.stringify (<anonymous>)
    at <anonymous>:1:6
*/


posted @ 2020-02-07 12:48  xgqfrms  阅读(4195)  评论(1编辑  收藏  举报