Within my project, I am utilizing a JavaScript language file that is structured as an object, where all language keys are properties of this object. For example: o_language['name'] = 'Name'
. Each PHP view has its own individual .js file, with each file containing a single object consisting of all the functions for that particular view. An example structure:
o_add_card = {
init: function(){...},
do_something: function(){..},
do_something_2: function(){..}
}
In the loader.js file, I load all the necessary objects. However, I am unsure about the most efficient way to call the language object in different scenarios.
1st method - Directly using the global o_language like so:
o_add_card = {
init: function(){...},
do_something: function(){
alert(o_language['name']);
},
}
2nd method - Assigning the global o_language to an object property:
o_add_card = {
lang: o_language['name'],
init: function(){...},
do_something: function(){
alert(this.lang['name']);
},
}
3rd method - Assigning the global o_language to an object property and creating a function variable:
o_add_card = {
lang: o_language['name'],
init: function(){...},
do_something: function(){
var o_lang = this.lang;
alert(o_lang ['name']);
},
}
4th method - Using the global o_language assigned to a function variable:
o_add_card = {
init: function(){...},
do_something: function(){
var o_lang = o_language['name'];
alert(o_lang ['name']);
},
}
Ultimately, I am trying to determine which approach is more efficient and whether it is something worth considering.