0

做这个apnagent 教程,我不明白在第二行设置值的“管道”的目的是什么。

var apnagent = require('apnagent')
  , agent = module.exports = new apnagent.Agent(); // <--- WHY this here

特别是我不明白为什么module.exports = agent;需要,如果在教程的前面有这样一行:

module.exports = "<a1b56d2c 08f621d8 7060da2b c3887246 f17bb200 89a9d44b fb91c7d0 97416b30>"; 

为什么module.exports需要覆盖?

4

2 回答 2

1

|实际上,它并不是真正的管道,在 Unix 世界中没有(管道)。

这种模式确保new apnagent.Agent()在本地范围内都可以agent通过requirevia访问module.exports

这与执行以下操作完全相同:

 var agent = new apnagent.Agent();
 module.exports = agent;
于 2016-11-16T10:24:05.273 回答
0

module.exports可以导出您的代码

new apnagent.Agent();创建一个新的代理对象

agent = module.exports = new apnagent.Agent();

module.exports = new apnagent.Agent(); agent = module.exports

他们是平等的。

Module.exports指向一个新对象,agent与引用断开连接module.exports,然后通过agent = module.exports重新导出module.exports

代理并将其分配给 module.exports,以便我们可以从所有或不同的游乐场场景访问它。

于 2016-11-16T10:46:20.023 回答