Lets say I have a javascript object with the the following
var Settings = function () {
this.timelimit = 0;
this.locked = false;
this.expires = null;
this.age = null;
};
And then I set some get/set functions like:
Settings.prototype = {
getAllAges: function () {
return self.age;
},
getTimeLimit: function () {
return self.timelimit;
},
load: function() {
data_from_local_storage = LoadLocalStorage();
}
}
In data_from_local_storage
I have JSON variables that match the above variables (timelimit
, locked
etc .. )
Issue is, the object var settings_ref = Settings()
have all these 4 variables - but also have these 3 functions assigned in settings_ref
- due to this OO behavior I need to write inside the load()
function:
this.timelimit = data_from_local_storage.timelimit
this.age = data_from_local_storage.age
this.locked = data_from_local_storage.locked
Because if I'll write
this = data_from_local_storage
it will destroy my object.
So how can I avoid writing all these variables one-by-one ?
- w/o a for loop inside a function
- in this example are just 4 but there are much much more and I cannot write it everywhere everytime
- I'm looking for some
.update()
function like in Python or something ..
Any quick shortcut that someone know ?