2014-10-29 158 views
0

我有3個文件,一個作爲main.coffee和2個其他文件:file1.coffee和file2.coffee具有不同的功能。我想使用的功能在我的主文件(包括C)如何使用功能從其他files.coffee

main.coffee

exemple1 = function1fromfiles1("hello") exemple2 = function1fromfiles2("hello")

file1.coffee

function1fromfiles1=(word)-> console.log "file1"+word return true

file2.coffee

function1fromfiles2=(word)-> console.log "file2"+word return true

我試圖與要求,但我有錯誤消息:

ReferenceError: function1fromfiles1 is not defined at Object.<anonymous> (/Users/admin/Documents/workspace/node/file1.coffee:3:1) at Object.<anonymous> (/Users/admin/Documents/workspace/node/file1.coffee:1:1) at Module._compile (module.js:456:26)

,如果有人能幫助我嗎?謝謝

回答

0

file1.coffee:

module.exports = (word)-> 
    console.log "file1"+word 
    return true 

file2.coffee:

module.exports = (word)-> 
    console.log "file2"+word 
    return true 

main.coffee:

function1fromfiles1 = require('./file1.coffee') 
function1fromfiles2 = require('./file2.coffee') 
exemple1 = function1fromfiles1("hello") 
exemple2 = function1fromfiles2("hello")