如何使用其他文件中的函数
How to use functions from an other files.coffee
我有三个文件,一个作为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")
相关文章:
- 通过Ajax将JavaScript函数传递给PHP文件
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- 从HTML调用typescript文件中的函数
- 如果使用javascript函数屏幕太小,我该如何更改HTML文件的背景色
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 为什么spyOn"停止函数“”的所有执行;Jasmine(要求澄清Jasmine 2.2间谍文件)
- 如何从onclick函数设置全局变量并将其传递给另一个JS文件
- 为什么jQuery文件的函数中有两个参数,但只接收一个参数
- 我可以将函数导入到typescript类文件中吗
- 如何调用extern.js文件中的函数
- 外部链接的Javascript文件赢得't执行,但函数有效
- 使用drupal中自定义javascript文件中的一个函数
- 将javascript变量从一个函数/文件传递到另一个
- 导入iPython自定义小部件函数(文件结构?)
- Wordpress-自定义页面包括第二个导致函数文件问题的自定义页面
- 调用外部js函数文件
- 如何快速识别被调用的Javascript函数文件
- 如何获得包含javascript函数文件的相对路径
- rails链接函数文件下载
- 如何将函数/文件导入到react native应用程序中?