Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming variables question 1

Status
Not open for further replies.

jaschulz

Programmer
May 20, 2005
89
FR
I need to create and destroy a group of objects the number of which varies at runtime. So, for instance, when the user clicks menuItem1, let's say I need 5 of these objects. Then when the user clicks another menuItem, I need to destroy the 5 existing objects and create, say, 3 new ones.

So, my question is: how do I write a variable declaration to accomodate this process. For instance, let's say I need objects:

object1 = new myObject(args)
object2 = new myObject(args)
object3 = new myObject(args)
object4 = new myObject(args)
object5 = new myObject(args)

Is there some way I can write a for loop to create these objects and give them the names above? If I could do this, then I could destroy them easily enough when I need to. (By the way, what happens to the variables when the objects they are associated with are destroyed?)

Thanks,

JAS
 
[tt]for (var i=1;i<=5;i++) {
window["object"+i]=new myObject(args);
}[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top