I want to seperate the language vars from my html libary but i'm not sure what the best approach for this is.
Currently I got something like this;
function putAlertA() { alert('This is alert a'); } function putAlertB() { alert('This is alert b'); } function setAlerts() { putAlertA(); putAlertB(); } Now i want to separate the strings from the functions:
Solution A
function putAlertA() { var strings = getLanguageVars(); alert(strings[0]); } function putAlertB() { var strings = getLanguageVars(); alert(strings[1]); } function setAlerts() { putAlertA(); putAlertB(); } function getLanguageVars() { var strings = new Array(); strings[0] = "This is alert a"; strings[1] = "This is alert b"; return strings; } Solution B
function putAlertA(strings) { alert(strings[0]); } function putAlertB(strings) { alert(strings[1]); } function setAlerts() { var strings = getLanguageVars(); putAlertA(strings); putAlertB(strings); } function getLanguageVars() { var strings = new Array(); strings[0] = "This is alert a"; strings[1] = "This is alert b"; return strings; } Solution C
function putAlertA() { var strings = window.strings; alert(strings[0]); } function putAlertB() { var strings = window.strings; alert(strings[1]); } function setAlerts() { putAlertA(); putAlertB(); } window.strings = new Array(); strings[0] = "This is alert a"; strings[1] = "This is alert b"; I think Solution C would be the best since I reckon solution A & B generates too much overhead in terms of memory consumption and it doesn't look quite logical since the language array is a global var. I'm however a bit hesitant in using window.. Not sure it's the right approach how to do this. Maybe there's a better way how to do this? I'm using jQuery
new Array(); 2) Use named string tables (objects where keys have some meaning) array indexes will get confusing; 3) Search, this question has been asked many times before.