怎么打印查看cc.node

一json.stringify就报 太多循环 无法打印,导致无法查看node里面存的数据,

TypeError: Converting circular structure to JSON
–> starting at object with constructor ‘Scene’
| property ‘_children’ -> object with constructor ‘Array’
| index 0 -> object with constructor ‘Node’
— property ‘_parent’ closes the circle

这个确定没内存泄漏吗 ,看着node里存了parent,然后再打印parent又到node反复循环

 let node = new cc.Node();
 node.customConfig = 1;
JSON.stringify(node)

顶呱呱顶呱呱顶呱呱

node里面为什么要存数据

也是个类,存储比较方便,就算不存数据,打印node理论上应该支持的,如老版的2d-js,unity

skipNodeStringify(obj) {
        let skipNodeJson = {
            "_objFlags": 0,
            // "_name": "New Node",
            "__editorExtras__": {},
            "_parent": "[Circular]",
            "_children": [],
            "_active": true,
            "_components": [],
            "_prefab": null,
            "_scene": "[Circular]",
            "_activeInHierarchy": true,
            "_id": "f9X3W8iudLcKvFpYQlftZs",
            "_eventProcessor": 1,
            "_eventMask": 1,
            "_siblingIndex": 4,
            "_originalSceneId": "",
            "_uiProps": 1,
            "_static": false,
            "_lpos": 1,
            "_lrot": 1,
            "_lscale": 1,
            "_mobility": 0,
            "_layer": 1073741824,
            "_euler": 1,
            "_transformFlags": 15,
            "_eulerDirty": false,
            "_flagChangeVersion": 149,
            "_hasChangedFlags": 7,
            "_pos": 1,
            "_rot": 1,
            "_scale": 1,
            "_mat": 1,
        };
        const seen = new WeakSet(); // 弱引用,避免内存泄漏
        let a = JSON.stringify(
            obj,
            (key, value) => {
                if (typeof skipNodeJson[key] != "undefined") {
                    return;
                }
                else if (typeof value === "object" && value !== null) {
                    if (seen.has(value)) {
                        return "[Circular]"; // 发现循环时替换
                    }
                    seen.add(value);
                }
                return value;
            }
        );
        return a;
    }

调用:

            let node = new cc.Node();
            node.zidingyi = 1;   
           node.parent = cc.director.getScene();
          skipNodeStringify (node)

输出:

{"_name":“New Node”,“zidingyi”:1}

先这样用着了