Variable in Meteor.js definieren

Wenn ich die Variable definierelists wie unten gezeigt und tippelists in der konsole bekomme ich den fehlerReferenceError: lists is not defined

var lists = new Meteor.Collection('Lists');

if (Meteor.isClient) {
  Template.hello.greeting = function () {
    return "my list.";
  };

  Template.hello.events({
    'click input' : function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

Es funktioniert nur, wenn ich deklarierelists als globale Variable:

lists = new Meteor.Collection('Lists');

Frage: Warum muss der Geltungsbereich global sein?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage