Pat
Pat

Reputation: 1208

What options are there for creating universally accessible javascript functions (on the client side) in Meteor?

I'm starting out with Meteor at the moment. As with any JS based project, it helps to have a little algorithm library somewhere that contains handy basic functions to invoke throughout the project code.

I'm still getting my head around the app infrastructure, so I am wondering two things about making functions universally accessible across the client side: 1) Where should the functions go? 2) What framework functionality should I use (or is used automatically) to make them available throughout the project?

Upvotes: 1

Views: 164

Answers (1)

saimeunt
saimeunt

Reputation: 22696

You should have a "client" folder in your Meteor root application directory. Inside it, create a "js" directory, and simply put your javascripts files in it. Then declare your global vars and functions this way :

myVar=VALUE;
myFunction=function(arguments){...};

Using the classic syntax (var myVar=VALUE;) will cause your symbols to be only local to the source file. In your "js" folder, you can play with the order in which scripts are loaded (read the docs for futher details), but basically, everything inside a "lib" folder gets loaded first, and inside folders, files are loaded using filename alphabetical order.

Upvotes: 1

Related Questions