2016-11-16 1 views
0

これを行うapnagenttutorialと2番目の行に設定値の「配管」の目的は何か分かりません。JavaScriptでの配管の目的は?

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を上書きする必要がありますか?

+2

これは 'agent = new apnagent.Agent();の略です。 module.exports =エージェント; ' – connexo

+0

なぜmodule.exportsを上書きする必要がありますか? –

+0

@Jánosそれは別のファイルにあります。 –

答えて

1

実際にはパイピングではありませんが、実際には、Unixの世界では|(パイプ)はありません。

このパターンはnew apnagent.Agent()module.exportsを介してローカルagentとスコープとrequire通じ両方でアクセス可能であることを確認します。

それはやってとまったく同じです:輸出あなたのコード

new apnagent.Agent();新しいエージェントオブジェクト

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

0123を作ることができます

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

module.exports

等しくなります。次いでagent = module.exports介して再輸出module.exportsに新しいオブジェクトに

Module.exports点、module.exports参照しagent切断、。

エージェントとそれをmodule.exportsに割り当てて、私たちがすべてのプレイグラウンドシナリオからアクセスできるようにします。

関連する問題