2
I need to create a Javascript code that returns an object already created with a dynamic reference by its name/id.
Basically this:
// Define class
function Test(num) {
    this.msg = "Message";   
    this.num = num;
}
// Create objects
var objTest_1 = new Test(1);
var objTest_2 = new Test(2);
var objTest_3 = new Test(3);
// Call objects in loop
for (i = 1; i <= 3; i++) { 
/*
    // Static reference
    alert( objTest_1.msg + objTest_1.num );
    //or
    alert( Object(objTest_1).msg + Object(objTest_1).num );
*/
    // Dinamic reference
    alert( Object("objTest_" + i).msg + Object("objTest_" + i).num );  // Return error "NaN"
}
Ps: In this example I just look for some "Property" of the object, but in my actual code I need to actually return an existing object to call a specific method that it contains.
The big question is that who generates the objects is the framework of the system I’m using, basically I can’t change the way they are built.
– lorduakiti
@lorduakiti this framework creates the objects with
vareven?– rdleal
@Panther would not know to inform you with full certainty but I believe so!
– lorduakiti