Inside the standard isClient
conditional I have a variable stored. Let's say I needed to access this from the window
, where would it be located?
if (Meteor.isClient) {
var people = new Meteor.Collection("people");
}
Thanks!
Inside the standard isClient
conditional I have a variable stored. Let's say I needed to access this from the window
, where would it be located?
if (Meteor.isClient) {
var people = new Meteor.Collection("people");
}
Thanks!
In Meteor client environment, every variable you declare without the var
keyword is accessible on the global object which is window
.
if (Meteor.isClient) {
people = new Meteor.Collection("people");
console.log(window.people._name); // displays "people" in the console
}
Variables declared with the var
keyword are file scoped, variables declared without the var
keyword are application scoped.
On the client, the global scope is the window
object, on the server, the global scope is the global
object.
When you declare a global variable in both environments, a property with this name is declared both on the window
object and the global
object, these two properties are distinct, if you modify the client one, it won't impact the server one.