如何使用其他文件中的函数

How to use functions from an other files.coffee

本文关键字:函数 文件 何使用 其他      更新时间:2023-09-26

我有三个文件,一个作为main.coffee,另外两个文件:具有不同功能的file1.coffee和file2.coffee。我想使用我的主文件中的函数(包括在C中)

main.coffee

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

file1.咖啡

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

file2.咖啡

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

我尝试了require,但我有错误消息:

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)

如果有人能帮我?感谢

file1.coffee:

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

file2.咖啡:

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")