JavaScript 中管道的用途?
Purpose of piping in JavaScript?
这样做 apnagent
tutorial 我不明白 'piping' 在第二行设置值的目的是什么。
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
需要覆盖?
这不是真正的管道,实际上,没有 Unix 世界中的 |
(管道)。
此模式确保 new apnagent.Agent()
在本地范围内可以通过 agent
访问,也可以通过 require
通过 module.exports
.
访问
完全一样:
var agent = new apnagent.Agent();
module.exports = agent;
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,以便我们可以从所有或不同的游乐场场景访问它。
这样做 apnagent
tutorial 我不明白 'piping' 在第二行设置值的目的是什么。
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
需要覆盖?
这不是真正的管道,实际上,没有 Unix 世界中的 |
(管道)。
此模式确保 new apnagent.Agent()
在本地范围内可以通过 agent
访问,也可以通过 require
通过 module.exports
.
完全一样:
var agent = new apnagent.Agent();
module.exports = agent;
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,以便我们可以从所有或不同的游乐场场景访问它。