Meteor variable scope (global, client, server, or all?)

不羁的心 提交于 2019-12-11 21:06:59

问题


I'm new to Meteor and I don't quite get the whether my variables will be available to the client or server or both.

var variable_1 = [];
if (Meteor.isClient) {
    var variable_2 = [];
}
if (Meteor.isServer) {
    var variable_3 = [];
}

In this example if I use Meteor.method in the server side on variable_1, will I be able to access whatever I just did to variable_1 from client? Can I access variable_2 with a method in Meter.isServer? What is the difference between the scope of variable_1 and variable_2? I'm guessing that variable_1 is accessible to both client and server, variable_2 is just client, and variable_3 is just server. However, I'm quite unsure about guess on the scope of variable_1. Does anyone know?


回答1:


This is really a JavaScript question. All variables will be available everywhere. That's because JavaScript doesn't have block scoping. It has some kind of function-scoping. Read the answer here for more info.



来源:https://stackoverflow.com/questions/31097549/meteor-variable-scope-global-client-server-or-all

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!