Thursday 15 March 2012

javascript - How to use functions from an other files.coffee -



javascript - How to use functions from an other files.coffee -

i have 3 files, 1 main.coffee , 2 other files : file1.coffee , file2.coffee different functions. want utilize function in main file (as include in c)

main.coffee

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

file1.coffee

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

file2.coffee

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

i tried require have error message:

referenceerror: function1fromfiles1 not defined @ object.<anonymous> (/users/admin/documents/workspace/node/file1.coffee:3:1) @ object.<anonymous> (/users/admin/documents/workspace/node/file1.coffee:1:1) @ module._compile (module.js:456:26)

if can help me? give thanks

file1.coffee:

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

file2.coffee:

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

main.coffee:

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

javascript node.js coffeescript include require

No comments:

Post a Comment