Setting object variables through JSON.
Hi.
I've started coding in a OOP manner. I need a way, to set all variables specified in a JSON object to a normal object. Right now I'm trying to use the call method, but I don't know what should I put where it says "WHATHERE?". For example:
-----------------------------------------
function myObject() {
this.myvarA = null;
this.myvarB = null;
}
function JSONproperties(arguments) {
for (property in arguments[0]) {
this.WHATHERE?= arguments[0][property]; //this should set the variable named property to the value in arguments[0][property]
}
}
var obj = new myObject;
JSONproperties.call(obj, {myvarA:'hello',myvarB:'hello2'});
-------------------------------------------
I've thought of using something like the setAttribute method like:
this.setAttribute(property,arguments[0][property])
but setAttribute is a thing for Elements, not for Objects.
What can I do?. Any help will be appreciated.
|