什么是“<ref *1>”?

The*_*adu 11 circular-reference node.js

根据主题,我在互联网上找不到任何与此相关的具体内容。

<ref *1>即使我将属性称为“树”,我在类名之前得到的输出中是什么?参考...什么,为什么如果我称之为财产?以及如何修复它?

CLI 输出:

> $ node binary-search-tree.js                                                                                                                                  
<ref *1> BinarySearchTree { tree: [Circular *1] }
Run Code Online (Sandbox Code Playgroud)

这是我的代码(学习算法):

> $ node binary-search-tree.js                                                                                                                                  
<ref *1> BinarySearchTree { tree: [Circular *1] }
Run Code Online (Sandbox Code Playgroud)

Azi*_*ova 10

这是用于显示循环引用的引用索引。

这意味着,您的对象中有一些圆形结构。

您还可以通过运行以下命令来查看它是循环的:

JSON.stringify(lolTree.tree)
Run Code Online (Sandbox Code Playgroud)

这将导致:

VM829:1 未捕获的类型错误:将循环结构转换为 JSON --> 从构造函数“BinarySearchTree”的对象开始 --- 属性“tree”在 JSON.stringify () 处关闭循环

当对象的属性引用对象本身时,就会发生这种情况。考虑代码:

// define some object
const a = { foo: 1 };

// add a property referring to the object
a.bar = a;

console.log(JSON.stringify(a)); // TypeError
Run Code Online (Sandbox Code Playgroud)