I’m using Tapestry5, jQuery, and JSON. I’m wondering how you would go about sharing json data between two jQuery files. My json data is being passed into file A init by my framework. I’m not sure how to get file B to work with File A. I would need changes to json data in file A to be available in file B and vice versa. My goal is to split up the functions of my javascript that all use the same JSON obj. I’m rather new to this, so perhaps I’m going about it all the wrong way.
File A
(function ($) {
T5.extendInitializers(function(){
function init(jsonData) {
//do something with jsonData
}
}
}
File B
(function ($) {
function init(jsonData) {
//do something with jsonData
}
}
The simple way to share them would be to make jsonData global. A slightly nicer version would be to wrap jsonData with a singleton.
Another way would be to just pass jsonData to both init functions. Javascript is pass by reference, so if you pass jsonData to both when you call both init functions, changes one function makes will be seen by the other.
More context would be needed to recommend what would actually be the best method.