0

My Meteor methods call generic/utility type of methods that I don't want to keep redefining in each collection file. As long as the method remains inside of the collection file, the method is accessible. Once the method is moved to a different file, this error is generated: ReferenceError: myMethod is not defined

The collection file is located in: lib/collections/posts.js If myMethod() is located in this posts.js file, it is accessible. If I create another file such as lib/_utils.js and move myMethod() there, it won't load. I intentionally added the underscore for it to load prior to the collection files.

The post titled Ordering of the css and js files loaded by Meteor explains the order in which the files are loaded, but something is still amiss. I'm guessing this is a security issue surrounding how Meteor methods work.

Can a Meteor method make a call to a method in another .js file? If so, where should this other .js file be located?

This question is answered in post Why can't my Meteor app recognize my function?

TH_
  • 97
  • 2
  • 9
  • http://vstark.net/2014/09/25/4-things-with-meteor/ also explains the order that Meteor loads the files. My file appears to be in line with this. – TH_ Aug 11 '15 at 18:04
  • possible duplicate of [Global variables in Meteor](http://stackoverflow.com/questions/27509125/global-variables-in-meteor) – Kyll Aug 11 '15 at 18:05
  • 1
    Also definitely a dupe of http://stackoverflow.com/questions/31929044/why-cant-my-meteor-app-recognize-my-function/31929174#31929174 – Michel Floyd Aug 11 '15 at 18:09
  • @MichelFloyd Maybe not, we would need to see some MCVE to be sure. – Kyll Aug 11 '15 at 18:10
  • True but function scope is such a common beginner problem. – Michel Floyd Aug 11 '15 at 18:13
  • Thanks, @MichelFloyd. https://stackoverflow.com/questions/31929044/why-cant-my-meteor-app-recognize-my-function/31929174#31929174 answers my question. This isn't a question about global variables, but how Meteor works. As you stated: "Meteor wraps all functions so that their scope is restricted to the file they are in unless they are defined as global functions." – TH_ Aug 11 '15 at 18:35
  • It's one of those things that you run to in the first 24h with Meteor. There will be more ;) – Michel Floyd Aug 11 '15 at 18:36

0 Answers0