Why not create the object explicitly? The syntax you have there is just another way of creating an object, so it's essentially the same as saying this:
var test = new Object();
test.prefix = "useMe";
test.v1 = test.prefix;
alert(test.v1);
If you'd prefer it a little more automated, you can create a constructor that would take in the prefix you want:
function test2(prefix)
{
this.prefix = prefix;
this.v1 = this.prefix;
}
var t2 = new test2("useMe");
alert(t2.v1);
This version passes in the prefix and automatically sets the v1 property to whatever it is you passed in. That can get unwieldy for large objects or if you need to do lots of reassignment, though. Regardless, hope that helps.
Main Topics
Browse All Topics





by: ryancysPosted on 2007-12-25 at 18:08:32ID: 20528189
perhaps:
v1 : eval(this.prefix+"_v1")
?