I am writing a JS script with 2 classes(Object, ClientUser), where ClientUser inhertrce from Object:
function Object() {
this.className;
this.properties;
this.editableproperties;
this.set = function(key, value) {
if (this.properties != undefined) {
this.properties[key] = value;
}
}
this.get = function(key) {
if (this.properties != undefined) {
return this.properties[key];
}
}
this.init = function(objectID, completionHandler) {
var getObjectURL = "/get_object_by_id";
perfromPostCall(getObjectURL, {
objectId: objectID,
className: this.className
}, function(result) {
if (result.success == true) {
for (var key in this.properties) {
alert("Find key:" + key);
this.set(key, result.object.get(key));
}
completionHandler(result);
} else {
completionHandler(result);
}
});
}
}
function ClientUser() {
ParseObject.prototype.constructor.apply(this);
this.className = "User";
this.properties = {
createdAt: null,
updatedAt: null,
objectId: null,
username: null,
password: null,
email: null,
dateOfBirth: null,
emailVarified: null,
address: null,
name: null,
type: null
};
}
function perfromPostCall(post_url, object, completionHandler) {
$.ajax({
url: post_url,
type: "post",
data: {
object: object
},
success: function(result) {
completionHandler(result);
},
error: function(error) {
var result = {
"succes": false,
"msg": error
};
completionHandler(result);
}
});
}
So actually every thing works as expected except: In the init method, after I performed the post call I want to iterate over the properties: this.properties, which should contain the values declared in ClientUser, but it´s null. Since I can call this.className(which returns the right value), before I call performPostCall, I guess it´s some problem regarding the inheritance strategy I use. I would really be pleased if you guys could help me out, thanks ;)