János János - 4 months ago 30
Javascript Question

Purpose of piping in JavaScript?

Doing this

tutorial and I do not understand what is the purpose of 'piping' of setting values in the second line.

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

Especially I do not understand why
module.exports = agent;
needs, if earlier in tutorial there is a line like this:

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

Why does
need to be overwritten?


It's not really piping, actually, there's no | (pipe) as in the Unix world.

This pattern makes sure new apnagent.Agent() is accessible in both the local scope with agent and through require via module.exports.

It's exactly the same as doing:

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