Say I have a function that returns a specific id of a player in a client side java-script file:
var playerId = function () {
return Player.findOne({current:true})._id;
};
However as the project has grown, I have started to break up my code into a variety of .js files (player.js, game.js, round.js, etc).The problem arises when I want to reuse the function. I cannot call the playerId() function from a different .js file. As of right now I am just copying and pasting the function into every .js file that utilizes it. Is there a place I can define the function so that it is available to every .js file?
The correct answer is simply to remove the var in the declaration statement of the variable you wish to export. http://docs.meteor.com/#namespacing
Also, make sure the load order is correct by following these rules : http://docs.meteor.com/#structuringyourapp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With