I'm currently facing difficulties in organizing my code efficiently.
Let me illustrate the structure I have in mind:
var Test = {
old: [
get: function(who, when){
returrn({ subject: "Old test 001", text: "The test 001 was perform by "+who });
},
get: function(who, when){
returrn({ subject: "Old test 002", text: "The "+when+" the test 002 was performed"});
}
],
new: [
//Same thing
]
};
The issue arises when trying to implement this structure as it seems not feasible. I am seeking advice on how to declare functions within an array. This is necessary because each method 'get()' of the array should return a different message and may include variables passed in parameters positioned differently within the text, thus requiring explicit declaration.
I've considered the following alternative approach:
var Test = {
old: [
one: {
get: function(who, when){
returrn({ subject: "Old test 001", text: "The test 001 was perform by "+who });
},
},
two: {
get: function(who, when){
returrn({ subject: "Old test 002", text: "The "+when+" the test 002 was performed"});
}
}
],
new: [
//Same thing
]
};
This option does not meet my requirements as I need to access the content dynamically, like
Test.old[test_id].get("toto", "02/04/2013")
. Unfortunately, indexing items by numerical values in JSON is not allowed.
If there's no better solution, I will proceed with this setup.
In this context, what would be the most suitable approach?
Thank you!