Update the URLs whenever you change the local storage values:
var AppUrl = { };
updateURLs('default');
function updateURLs(tmpAdd) {
window.localStorage.setItem('TmpAdd', tmpAdd);
AppUrl.jsonUrl1 = 'http://myurl.com/' + tmpAdd;
AppUrl.jsonUrl1 = 'http://myurl.com/category/' + tmpAdd;
}
function slideonlyone(item) {
updateURLs(item);
console.log(window.localStorage.getItem('TmpAdd'));
console.log(AppUrl.jsonUrl1);
}
Another way would be to turn jsonUrl1
and jsonUrl2
into functions that look at the current value of localStorage.TmpAdd
and create a URL appropriately. You could make the functions look like ordinary properties by using custom property gettersMDN, but this is probably an overkill.
var AppUrl = {
'jsonUrl1' : function() {
return 'http://myurl.com/' +
window.localStorage.getItem('TmpAdd');
},
'jsonUrl2' : function() {
return 'http://myurl.com/category/' +
window.localStorage.getItem('TmpAdd');
}
};
// usage: replace AppUrl.jsonUrl1 with AppUrl.jsonUrl1()