在Nodejs中,当我在console.log中有一个req对象时,[Circular]是什么意思?
这是针对基本nodejs示例的示例console.log(req)。请注意,request.socket._readWatcher.socket是[Circular]。这是否意味着它指的是自己?我怎样才能取消引用?
{ socket:
{ bufferSize: 0,
fd: 7,
type: 'tcp4',
allowHalfOpen: true,
_readWatcher:
{ socket: [Circular],
callback: [Function: onReadable] },
destroyed: false,
readable: true,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher:
{ socket: [Circular],
callback: [Function: onWritable] },
writable: true,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
remoteAddress: '127.0.1.1',
remotePort: 40407,
server:
{ connections: 1,
allowHalfOpen: true,
watcher: [Object],
_events: [Object],
httpAllowHalfOpen: false,
type: 'tcp4',
fd: 5 },
ondrain: [Function],
_idleTimeout: 120000,
_idleNext:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idlePrev:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idleStart: Sun, 15 May 2011 01:18:50 GMT,
_events:
{ timeout: [Function],
error: [Function],
close: [Function] },
ondata: [Function],
onend: [Function],
_httpMessage:
{ output: [],
outputEncodings: [],
writable: true,
_last: false,
chunkedEncoding: true,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
_hasBody: true,
_trailer: '',
finished: false,
socket: [Circular],
connection: [Circular],
_events: [Object],
_header: 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n',
_headerSent: false } },
connection:
{ bufferSize: 0,
fd: 7,
type: 'tcp4',
allowHalfOpen: true,
_readWatcher:
{ socket: [Circular],
callback: [Function: onReadable] },
destroyed: false,
readable: true,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher:
{ socket: [Circular],
callback: [Function: onWritable] },
writable: true,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
remoteAddress: '127.0.1.1',
remotePort: 40407,
server:
{ connections: 1,
allowHalfOpen: true,
watcher: [Object],
_events: [Object],
httpAllowHalfOpen: false,
type: 'tcp4',
fd: 5 },
ondrain: [Function],
_idleTimeout: 120000,
_idleNext:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idlePrev:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idleStart: Sun, 15 May 2011 01:18:50 GMT,
_events:
{ timeout: [Function],
error: [Function],
close: [Function] },
ondata: [Function],
onend: [Function],
_httpMessage:
{ output: [],
outputEncodings: [],
writable: true,
_last: false,
chunkedEncoding: true,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
_hasBody: true,
_trailer: '',
finished: false,
socket: [Circular],
connection: [Circular],
_events: [Object],
_header: 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n',
_headerSent: false } },
httpVersion: '1.1',
complete: false,
headers:
{ 'user-agent': 'curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18',
host: 'uh-uh-uh-I-aint-telling',
accept: '*/*' },
trailers: {},
readable: true,
url: '/',
method: 'GET',
statusCode: null,
client:
{ bufferSize: 0,
fd: 7,
type: 'tcp4',
allowHalfOpen: true,
_readWatcher:
{ socket: [Circular],
callback: [Function: onReadable] },
destroyed: false,
readable: true,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher:
{ socket: [Circular],
callback: [Function: onWritable] },
writable: true,
_writeImpl: [Function],
_readImpl: [Function],
_shutdownImpl: [Function],
remoteAddress: '127.0.1.1',
remotePort: 40407,
server:
{ connections: 1,
allowHalfOpen: true,
watcher: [Object],
_events: [Object],
httpAllowHalfOpen: false,
type: 'tcp4',
fd: 5 },
ondrain: [Function],
_idleTimeout: 120000,
_idleNext:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idlePrev:
{ repeat: 120,
_idleNext: [Circular],
_idlePrev: [Circular],
callback: [Function] },
_idleStart: Sun, 15 May 2011 01:18:50 GMT,
_events:
{ timeout: [Function],
error: [Function],
close: [Function] },
ondata: [Function],
onend: [Function],
_httpMessage:
{ output: [],
outputEncodings: [],
writable: true,
_last: false,
chunkedEncoding: true,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
_hasBody: true,
_trailer: '',
finished: false,
socket: [Circular],
connection: [Circular],
_events: [Object],
_header: 'HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n',
_headerSent: false } },
httpVersionMajor: 1,
httpVersionMinor: 1,
upgrade: false }
由于我显然不是很清楚,我怎样才能取消引用循环引用的元素?它总是父元素吗?
另外值得注意的是,昨晚我了解了Utils类和检查方法。这可能会给我更多关于这方面的信息,而不是我应该知道的;)
答案 0 :(得分:16)
这是一个循环参考。就是这样。
示例:强>
a.b = a
现在登录:
[Object a] {
b: [Object a] {
b: [Object a] {
b: [Object a] {
b: [Object a] {
b: [Object a] {
b: [Object a] {
... welcome to recursion!
}
}
}
}
}
}
}
永远不会结束,log
调用会产生堆栈溢出,就是这样。节点检测到这些并改为给出循环引用文本。
答案 1 :(得分:10)
[Circular]
仅表示循环引用。
var o = {
"self": o
}
显示为
{
"self": [Circular]
}
可以显示为
{
"self": {
"self": {
"self": {
...
}
}
}
}
在你的情况下,socket
是外部套接字。
_idleNext
和_idlePrev
也指向外部。
<强>更新强>
_idleNext: // This one!
{ repeat: 120,
_idleNext: [Circular],
{ socket: // this one!
{ bufferSize: 0,
fd: 7,
type: 'tcp4',
allowHalfOpen: true,
_readWatcher:
{ socket: [Circular],
callback: [Function: onReadable] },
destroyed: false,
readable: true,
_writeQueue: [],
_writeQueueEncoding: [],
_writeQueueFD: [],
_writeQueueCallbacks: [],
_writeWatcher:
{ socket: [Circular],
答案 2 :(得分:2)
request.socket._readWatcher.socket == request.socket
与其他[循环]参考文献类似。
您不应该取消引用它们,因为它会导致未定义的行为(具有套接字的对象需要该引用才能正常工作)。