1

My Problem

While using Meteor JS I ran into something that I wasn't quite sure how to fix because everything seems to be loading in the corrector order. It still isn't acting in the correct way it is saying that the functions are not defined.

I have viewed other questions, most of which refer to the meteor methods section. I'm a little confused as to why I would need to wrap that in a Method object in order for all of them to be used.

My question is how would I get multiple functions and "faux" classes to be used as shared javascript files without using the meteor methods call and putting them in as sub objects.

Sample Class I'm trying use as shared js.

function CustomerProjects(){
  // declare variables
  this.name = null;
  this.scope = null;
  this.time = null;
  this.completed = false; // set every project to default false
  this.description = null;

  // Get the time array
  this.billableHours  = function(){
    if(this.completed){
      var totalTime = 0; // int
      var time = this.time;
      // calculate time
      for(var i = 0; i < time.length; i++){
          totalTime = totalTime + time[i];
      }
      return totalTime;
    } else {
      return "Not Completed";
    }
  };
} 

My File Structure

fasic file structure

David J. Davis
  • 906
  • 7
  • 20
  • possible duplicate of [Global variables in Meteor](http://stackoverflow.com/questions/27509125/global-variables-in-meteor) – Kyll Sep 08 '15 at 15:56

1 Answers1

2

Your definition is file-scoped, change it to global scope:

function CustomerProjects(){  // file scoped
..

CustomerProjects = function (){  // global scoped
..
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71