473,799 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatically create new objects? (with programmatic names)

2 New Member
I'm trying to create a new object to use as an associative array automatically.

I can programmaticall y create new variables like this:
Expand|Select|Wrap|Line Numbers
  1. for (var i; i < 10; i++) {
  2.   window["foo" + i];
  3.   window["foo" + i] = "moo" + i;
  4. }
  5. // now I have foo0,foo1, foo2, foo3... foo9
  6.  
And I can create a new object like this:
Expand|Select|Wrap|Line Numbers
  1. var myObject = new Object();
  2.  
but I don't know how to create for example
Expand|Select|Wrap|Line Numbers
  1. for (...) {
  2.   var myObject + i = new Object();
  3. }
  4.  
I want to do this because I'm going to make a cgi call to a C program which includes a date range parameter and various other things. Once I get a large array back I'm going to calculate median, standard deviation, spikes, etc. I want to save the array and those calculations in an object, since I'll potentially get 40 different results back. If I save these properties, then I can cache the calculations and cgi query results, so I don't have to make the same request/calculations twice.

So, I'd like the object name to be something close to my cgi query string. Then before I make the query again, I can see if I already have the object. If I do, I have the data, and the calculations.

When a new date range is selected, though, I would like to be able to delete all the cached objects so they aren't eating browser memory.

Any pointers?

I can do this with a whole slew of automatically created variables, but it would be nicer and more logical to do via objects.
May 14 '07 #1
2 2378
pbmods
5,821 Recognized Expert Expert
I want to do this because I'm going to make a cgi call to a C program which includes a date range parameter and various other things. Once I get a large array back I'm going to calculate median, standard deviation, spikes, etc. I want to save the array and those calculations in an object, since I'll potentially get 40 different results back. If I save these properties, then I can cache the calculations and cgi query results, so I don't have to make the same request/calculations twice.
You actually had it pretty much; just combine what you were doing:

Expand|Select|Wrap|Line Numbers
  1. for(var $i = 0; $i < 10; $i++)
  2.     window['myObject' + $i] = {};    //    or = new Object(); your choice...
  3.  
  4. //    E.g.:
  5. for(var $r = 0; $r < 10; $r++)
  6.     for(var $c = 0; $c < 10; $c++)
  7.         window['myObject' + $r][$c] = ($r * $c);
  8.  
  9. //    Etc....
  10.  
May 15 '07 #2
roadworrier
2 New Member
window['myObject' + $i] = {};
Perfect! Thanks. It appears to do just what I want in my tests. Somehow I didn't think I could create objects as properties of the object 'window' the way I could with regular variables/properties.

Much appreciated.
May 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1187
by: trbeals | last post by:
I'm trying to unserialize objects that are part of an inheritance hierarchy. The advice in 36.8 of the FAQ seems perfect for what I'm doing, except it leaves one critical question unanswered: how do I populate the map that takes derived class names and gives me the appropriate derived class constructor (or, alternatively, a representative object of the appropriate derived class)? Of course, I can always populate the map manually in...
11
11993
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in order to manage the databases more efficiently. - I'm currently using MySQL 4.1.12 and I'm currently testing 5.0.14 - I have a databases for each user account. - Each database has the same schema and entity relation model.
5
3756
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for Office 2000. I am creating a database to track student athletes. I have created the following tables. The table title is to the far left, with fields under each. The common field will be the StudentID field, which is their student number assigned...
6
1751
by: HD | last post by:
Hello. For the following, I would appreciate if anyone could tell me: if it can be done, how it might done, and/or what search terms I could use to find the solution myself. I would like to create a database in which _adding a new record automatically creates a new field in the table_ (ideally, deleting a record would also delete the field that was created when that record was added). Thus, the number of fields in the table would...
5
1925
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2; // ... public static MyObject Object400;
37
5095
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend timestamps on each line. I would like for this to work for all the printf-line functions (fprintf, etc...) as well as C++ I/O streams (cout and cerr). The key here is that I would like to get these timestamps on the lines of text written to...
23
7422
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
4
3833
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without saying I'm not asking you to solve the question - that won't help come exam time :(). Anyway I have a CSV delimited file in the following format; STRING,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT ...
23
1703
by: gu | last post by:
hi to all! after two days debugging my code, i've come to the point that the problem was caused by an unexpected behaviour of python. or by lack of some information about the program, of course! i've stripped down the code to reproduce the problem: <code> a = {} for x in range(10):
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.