call functions from separate files with Meteor

前端 未结 2 1499

I want to create an application in Meteor, from what I understand the manual it first loads which are in subdirectories, and then follows the alphabetical order. My file structu

相关标签:
2条回答
  • 2021-02-03 21:16

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

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

    0 讨论(0)
  • 2021-02-03 21:25

    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.

    0 讨论(0)
提交回复
热议问题