javascript - Defining variable in Meteor.js -


when define variable lists shown below , type lists in console, error referenceerror: lists 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, available in 'this'       if (typeof console !== 'undefined')         console.log("you pressed button");     }   }); }  if (meteor.isserver) {   meteor.startup(function () {     // code run on server @ startup   }); } 

it works if declare lists global variable:

lists = new meteor.collection('lists'); 

question: why must scoped global?

to access lists in console need use global scope console outside scope of file console considered own file.

with var can access lists anywhere in file.

in essence each file wrapped in function() {..}. why each file's variables can't accessed outside of them.

the reason variable scoping exists more complicated, more related third party packages/npm modules. each package needs have own scope wont have name collisions stuff outside.

if want able use more put in /compatibility folder too.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -