找出这个生成式循环检测器为何把共享子对象报告成循环。
JavaScript
function containsCycle(root) {
const seen = new WeakSet();
function visit(value) {
if (value === null || typeof value !== 'object') return false;
if (seen.has(value)) return true;
seen.add(value);
return Object.values(value).some(visit);
}
return visit(root);
}
const address = { country: 'FR' };
const order = { billing: address, shipping: address };
console.log(containsCycle(order));