exports module.exports

2764 단어 node.jsNodeJS
node. js 에 서 는 모든 파일 에 모듈 이 있 습 니 다.모듈 간 의 상호 관 계 는 반드시 변수, 함수, 또는 대상 을 드 러 내야 한다.
노출: module. exports 또는 exports 의존: require ()
인터넷 강의 module.exportsexports 의 글 이 특히 많 기 때문에 본문 을 쓰 는 것 은 필 기 를 하기 위해 서 이다.
require () 의 반환 값 은 module. exports 입 니 다. 이 대상 은 exports 대상 을 볼 수 없습니다.
node. js 는 각 모듈 (파일) 에 다음 코드 를 추가 합 니 다.
module.exports = exports = {};

//...
exports 단지 module.exports 의 인용 일 뿐이다.부적 절 한 예 를 들 어 module.exports 회사 exports 는 프로그래머 (당신) 회사 가 너무 작 으 니 참 으 세 요.
module.exports = exports = {};

exports.c = //...
exports.java = //...
exports.ruby = //...
exports.node = //...

당신 이 쓴 것 은 c, 자바, ruby 또는 node 든 모두 회사 의 회사 입 니 다. 만약 당신 이 어느 날 프로그램 을 쓰 지 않 는 다 면 회 사 는 화 를 낼 것 입 니 다. 당신 이 앞으로 프로그램 을 쓰 는 것 을 나 도 원 하지 않 습 니 다.
module.exports = exports = {};

exports.c = //...
exports.java = //...
exports.ruby = //...
exports.node = //...
exports=//...          
exports.php = //...            

지금 이 럴 때, 당신 이 이전에 쓴 것 은 회사 에서 도 사용 할 것 입 니 다. 당신 이 변 한 후부 터 회 사 는 당신 의 절 차 를 감히 사용 하지 못 합 니 다. 회 사 는 다른 사람 을 초빙 해 야 합 니 다.
module.exports = exports = {};

exports.c = //...
exports.java = //...
exports.ruby = //...
exports.node = //...
exports=//...          
exports.php = //...            
module.exports = //...   ,           ,               

그럼 우 리 는 언제 exports 를 사용 합 니까? 언제 module.exports 를 사용 합 니까?
To add functions and objects to the root of your module, you can add them to the special exports object. If you want the root of your module’s export to be a function (such as a constructor) or if you want to export a complete object in one assignment instead of building it one property at a time, assign it to module.exports instead of exports.
무슨 뜻 이 죠?
만약 당신 의 모듈 이 일부 방법 과 대상 을 다른 사람 에 게 노출 시 키 기 를 원한 다 면, 이 를 exports 속성 에 추가 하 십시오. 만약 당신 의 모듈 이 구조 함수 나 완전한 대상 을 노출 시 키 기 를 원한 다 면 module.exports결론: 네가 쓰 고 싶 은 대로 써 라. exports 에 직접 값 을 부여 하지 않 으 면 된다.

좋은 웹페이지 즐겨찾기