2014-11-27 2 views
0

내가 아닌 다른에서는, Cannot call method 'checkId' of undefinednode.js 하나의 모듈에 직면하고의 정의되지 않은 방법 'checkId'을 호출 할 수 없습니다, 호출 할 때 :형식 오류 : 때문에 널 (null) 프로토 타입

res = EntityCommons.prototype.checkId(res,json[RE_FIELD_ID]); 

내가 3 개 node.js 모듈이 Host, Request 동일한 디렉토리에 EntityCommons이 있습니다.

Request를 들면 다음과 같습니다 :

var EntityCommons = require("./EntityCommons.js"); 

console.log("XXEntityCommons null or undefined : " + 
    _.isNullOrUndefined(EntityCommons)); 
console.log("XXEntityCommons prototype null/und: " + 
    _.isNullOrUndefined(EntityCommons.prototype)); 

Host를 들어 다음과 같은 HostRequestEntityCommons을 필요로

var EntityCommons = require("./EntityCommons.js"); 

console.log("EntityCommons null or undefined : " + 
    _.isNullOrUndefined(EntityCommons)); 
console.log("EntityCommons prototype null/und: " + 
    _.isNullOrUndefined(EntityCommons.prototype)); 

I 출력을 선택하면, 내가 얻을 :

EntityCommons null or undefined : false 
EntityCommons prototype null/und: true 
XXEntityCommons null or undefined : false 
XXEntityCommons prototype null/und: false 

01 년, EntityCommons의 프로토 타입은 null입니다. 이것은 말이되지 않습니다. 무엇이이 문제를 일으킬 수 있습니까?

var Host = require("./Host.js"); 

이이 순환 문제인가 :

업데이트

EntityCommons은 다음과 너무 Host이 필요?

+1

이 순환 문제인가 : 그것은 또한 객체와 함께 작동

function EntityCommons() { } module.exports = EntityCommons; 

: 즉

, 내 모듈의 상단에있는 함수를 수출에 의해 시작? 예. 이 http://nodejs.org/api/modules.html#modules_cycles 단락의 이유 설명 –

답변

0

here의 권장 사항을 사용하여 순환 문제를 해결했습니다.

var EntityCommons = {}; 

module.exports = EntityCommons;