We are rewriting the jQuery code of our web service and we are thinking on a better way to organize it. We've been reading several SO questions, articles, etc; and this is a first approach, but we would love to receive feedback.
We are going to have a Class for each object of the page (Place, User, etc). We are planning to use Low Pro (Article) so we have all the code in one place.
However there are some variables that we need to pass from PHP (user.id, user.name, etc). We have thought the best way is to print a json and pass it to a general class.
var array = {
'key1' => 'value',
'key2' => 'value',
'key3' => 'value',
};
var te = new TE(array);
TE.js will assign variables there so the other classes can use them. As we have a multilingual web, we need to have the messages in several languages. We will do something similar to the answers of Multilingual alert messages in JavaScript
What do you think? Is there a better way to load the initial array? Any other suggestion or article?
Thanks!
We are finally using Classy.js for having Classes. We have built our own main Class that loads the params we print as a json on the data-params
attribute of the body
tag.
We have the translation string for the js classes on two different fields as Tom and Shan suggested.