在 Nodejs 中,当我 console.log 一个 req 对象时,[Circular] 引用了什么?如何确定 [英] In Nodejs, when I console.log a req object, what does [Circular] reference? How to determine that

查看:18
本文介绍了在 Nodejs 中,当我 console.log 一个 req 对象时,[Circular] 引用了什么?如何确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Nodejs中,当我console.log一个req对象时,[Circular]是什么意思?

In Nodejs, when I console.log a req object, what does [Circular] mean?

这是一个针对基本 nodejs 示例的示例 console.log(req).注意 request.socket._readWatcher.socket 是一个 [Circular].这是否意味着它指的是自己?我该如何取消引用?

Here's an example console.log(req) against a basic nodejs example. Notice the request.socket._readWatcher.socket is a [Circular]. Does that mean it refers to itself? How can I dereference that?

{ 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 }

更新

由于我显然没有尽可能清楚,我如何取消引用循环引用的元素?总是父元素吗?

UPDATE

Since I apparently wasn't as clear as I could have been, how can I dereference what element is being referenced circularly? Is it always the parent element?

另外值得注意的是,昨晚我了解了 Utils 类和检查方法.这可能会给我提供比我合理想知道的更多的信息;)

Also of note, last night I learned about the Utils class, and the inspect method. Which will probably give me way more information about this than I should reasonably want to know ;)

推荐答案

[Circular] 仅表示循环引用.

var o = {
    "self": o
}

显示为

{
    "self": [Circular]
}

可以显示为

{
    "self": {
         "self": {
              "self": {
                   ...
              }
         }
    }
}

在您的情况下 socket 是外部套接字.

In your case socket is the outer socket.

而且 _idleNext_idlePrev 也指向外面的.

And _idleNext and _idlePrev also point to the outer ones.

更新

_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],

这篇关于在 Nodejs 中,当我 console.log 一个 req 对象时,[Circular] 引用了什么?如何确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆