2014-01-08 3 views
1

밥상을 통과, 왜 하나 개의 작품을, 다른 오류가 발생하지 :커피 스크립트 다음 두 문장의 차이를 알아 내려고 노력하고, 변수

작품 :

jsonFileContents = fs.readFileSync('sample.json', 'utf8') 
res.send(jsonFileContents) 

것은하지 않습니다 :

던져
jsonFileContents = fs.readFileSync('sample.json', 'utf8') 
returnResult(jsonFileContents) 

returnResult = (data) -> 
    res.send data 

오류 :

`TypeError: undefined is not a function` 
+0

사람, 난 그냥 여기서 뭔가를 테스트 :) 동기되고,이보고이 기능을 충분히 알고 난 :) 감사 물어 줄 알았는데! – Cmag

답변

1

returnResult가 사용시 정의되지 않았기 때문입니다.

다음은 작동합니다 :

returnResult = (data) -> 
    res.send data 

jsonFileContents = fs.readFileSync('sample.json', 'utf8') 
returnResult(jsonFileContents) 
+0

그래서 returnResult를 호출 위에 놓으면이 문제가 해결됩니까? – Cmag

+0

@Cmag 예, returnResult는 사용하기 전에 정의되기 때문에 그렇습니다. – aknuds1

관련 문제