Reputation: 3682
From my understanding on the server a Meteor application runs in a single thread in a node.js fibers. In the client, the code runs in the global window.
What then is the safest and best practice for defining objects and methods in a Meteor application both on server side and client side?
In which cases would variables passed to the method be safe and not overwritten by another call to the method?
Static?
var myObj = {};
myObj.someFunc = function(){...};
As a standard object definition var myObj = function () { this.x = function () {...}; };
var myObj = new MyObject();
As a method of prototype?
function MyObject() { ... }
MyObject.prototype.someFunc = function() { }
var myObj = new MyObject();
While I believe I understand static objects, objects and prototypes and have done some experiments with console and Meteor in these regards I am still a noob and very green and I am uncertain and would like the advice of more experience and seasoned developers.
Thanks S
Upvotes: 0
Views: 223
Reputation: 2141
Not sure what you are asking here, but the example projects are the best place to look for the style of code suited to meteor development: http://www.meteor.com/examples/
You'll see that grouping client side js into a 'client' folder and server-side js into a 'server' folder is how the framework operates.
Client side methods are typically defined with
var game = function () {};
Server side methods are declared inside a Meteor.methods call (see http://docs.meteor.com/#meteor_methods):
Meteor.methods({
start_new_game: function (evt) {};
});
Hope that helps.
Upvotes: 0