Meteor JS共享方法和对象

时间:2015-09-08 14:39:55

标签: javascript meteor

我的问题

在使用Meteor JS时遇到了一些我不太确定如何修复的东西,因为一切似乎都在纠正器顺序中加载。它仍然没有以正确的方式表示没有定义功能。

我查看了其他问题,其中大部分都是关于流星方法的部分。我有点困惑的是为什么我需要将它包装在一个Method对象中,以便使用它们。

我的问题是如何获得多种功能以及" faux"用作共享javascript文件的类,不使用meteor方法调用并将它们作为子对象放入。

样本类I尝试用作共享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";
    }
  };
} 

我的文件结构

fasic file structure

1 个答案:

答案 0 :(得分:2)

您的定义是文件范围的,将其更改为全局范围:

function CustomerProjects(){  // file scoped
..

CustomerProjects = function (){  // global scoped
..
相关问题