【问题标题】:What is the difference between net.connect and net.createConnection in node.js?node.js 中的 net.connect 和 net.createConnection 有什么区别?
【发布时间】:2017-01-17 10:13:33
【问题描述】:

我正在阅读 Node.js 中 net 模块的文档,我看不出方法 net.connect 和 net.createConnection 之间有什么区别。

它们是完全相同还是有一些不同?

【问题讨论】:

    标签: javascript node.js sockets


    【解决方案1】:

    没有区别。这是source code的摘录:

    exports.connect = exports.createConnection = function() {
    

    我同意文档在这一点上并不清楚。

    【讨论】:

    • 现在更好的问题是:为什么他们创建同义词却为每个同义词提供不同的文档?
    【解决方案2】:

    完全相同,只是名称不同,形成源代码

    net.createConnection() 创建一个 net.Socket 对象并立即 对其调用 net.Socket.connect()。

    还有来自 Net 模块的62 行的源代码。

    exports.connect = exports.createConnection = function() {
      stuff
    };
    

    他们为什么这样做,我不知道。只需选择您喜欢的命名约定即可:)

    【讨论】:

      猜你喜欢
      • 2011-12-29
      • 2013-12-02
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      相关资源
      最近更新 更多