2016-11-16 1 views
0

이런 식으로 apnagenttutorial 그리고 두 번째 줄에 값을 설정하는 'piping'의 목적이 무엇인지 이해가되지 않습니다.JavaScript로 파이핑하는 목적은 무엇입니까?

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

module.exports이 필요합니까 덮어 쓸 수 : module.exports = agent; 요구,이 같은 라인이되는 튜토리얼 이전의 경우 왜

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

은 특히 이해가 안 돼요?

+2

'agent = new apnagent.Agent();의 약어입니다. module.exports = agent;'. – connexo

+0

module.exports를 덮어 써야하는 이유는 무엇입니까? –

+0

@ János 다른 파일에 있습니다. –

답변

1

실제로 파이핑이 아니며 실제로는 유닉스 세계에서와 마찬가지로 | (파이프)이 없습니다.

이 패턴은 new apnagent.Agent()module.exports을 통해 지역 agent와 범위와 require을 통해 모두 액세스 할 수 있는지 확인합니다.

그것은 정확히 수행과 동일합니다 :

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

module.exports 수출 코드

new apnagent.Agent();가 새 에이전트 오브젝트를

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

0123을 만들 수 있습니다

등가입니다. 다음 agent = module.exports 통해 새로운 객체

Module.exports 가리킨 module.exportsagent 참조 단절, 재를 내보낼 module.exports.

요원을 module.exports에 할당하면 모든 또는 다른 놀이터 시나리오에서 액세스 할 수 있습니다.