Although my title seems kinda wonky, I tried to describe exactly what I am trying to do. Say I have an object:
function testObj(data) {
this.id = data.id
this.getObjFromId = function() {
//Return some value from somewhere using the this.id
}
this.obj = this.getObjFromId();
}
The reason for doing this is so I can update the this.id property and this.obj will always return some other object using the updated id. Right now what this does is it initially calls the getObjFromId function using the original id and stores the returned value in this.obj. If I do something like this:
var testObj = new TestObj({id: 1});
alert(testObj.obj); //Returns Foo1
testObj.id = 5; //Update the object with a new id
alert(testObj.obj); //Returns Foo1, but should return Foo5
This would be simple if I could just call the this.obj function as a function like this.obj(), but for a variety of reasons this is not possible (templating etc etc.) so I need to be able to get a dynamic value from the this.obj "function" by simple using this.obj.
I hope this makes sense. As i'm writing I understand its confusing, so maybe there is a better approach to doing this. None the less, the functionality I am proposing needs to work the same where I can call a dynamic value from an object property. My questions title might be better suited as something more descriptive of my problem if someone cares to update, but I couldn't think of a better way to describe.