Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor function define across all .js project files

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?

like image 583
Nate Avatar asked Feb 25 '26 10:02

Nate


1 Answers

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

like image 138
saimeunt Avatar answered Feb 27 '26 00:02

saimeunt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!