call functions from separate files with Meteor

和自甴很熟 提交于 2019-12-02 21:51:47

Define the function with makeBoard = function() { ... }.

Functions defined with function foo() { ... } are local to the file, as are variables defined with var bar = ....

Using a globally defined variable, as avital suggests, will work, but is not a recommended code design choice (see JS mistake 1 listed here).

Instead in your lib directory you could create a file with:

Meteor.myFunctions = {
...
    makeBoard : function() { ... },
...
}

Then in any other js file you could call Meteor.myFunctions.makeBoard(). This should be done in the lib directory because Meteor guarantees the js files in lib are loaded before other directories, so your function will already be loaded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!