By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,255 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,255 IT Pros & Developers. It's quick & easy.

Problem with inheritance

Claus Mygind
100+
P: 571
I am trying to create a custom object, with objects that have objects. My problem is with the last object in the chain (sample), rather than create an additional object for a new value it simply replaces the existing value.

More specifically this is the structure I am looking for:
(I have included two sample data sets and my code below)

Job (only one value)
Boring (one or more occurrences)
Sample(one or more occurrences)
sample properties (20 different properties for each sample)

74550
12
1
sampledate
depth
blows
.
.
.
2
sampledate
depth
blows
.
.
.

here is the sample data
Expand|Select|Wrap|Line Numbers
  1. "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
  2. "74550 12   1",74550,"12   ","1   ","2009-12-17","1-2.5      ","2-2-3      ","390","44.7","34.2","11.2","68.7","34.2","1087.7","1086.3","0.9","0.0","0.00","0.000","0.0"," ","","1.5        ",""," Black and Gray silty CLAY little sand trace gravel and organic very moist CL - FILL                                                                                                                                                                          ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  3. "74550 12   2",74550,"12   ","2   ","2009-12-17","3.5-5      ","2-3-3      ","391","56.6","46.5","11.1","77.8","46.7","1108.1","1086.1","0.8","0.0","0.00","0.000","0.0"," ","1.03 ","1.25       ",""," Brown +  Gray silty CLAY little sand trace roots very moist CL                                                                                                                                                                                               ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  4. "74550 12   3",74550,"12   ","3   ","2009-12-17","6-7.5      ","1-1-2      ","392","60.5","49.8","11.1","78.3","38.6","1107.5","1084.9","0.8","0.0","0.00","0.000","0.0"," ","0.50 ","0.50       ",""," Brownish Gray silty CLAY little sand very moist CL                                                                                                                                                                                                           ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  5. "74550 12   4",74550,"12   ","4   ","2009-12-17","8.5-10     ","1-2-2      ","393","53.3","42.4","11.2","74.1","31.4","1108.4","1086.3","0.8","0.0","0.00","0.000","0.0"," ","","0.25       ",""," Gray silty CLAY little sand very moist CL                                                                                                                                                                                                                    ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  6. "74550 12   5",74550,"12   ","5   ","2009-12-17","11-13      ","2-2-2-3    ","394","55.4","45.7","11.1","78.1","35.0","1108.7","1087.8","0.8","0.0","0.00","0.000","0.0"," ","0.63 ","1.0        ",""," Gray silty CLAY little sand trace organic very moist CL                                                                                                                                                                                                      ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  7. "74550 12   6",74550,"12   ","6   ","2009-12-17","13-15      ","5-6-7-8    ","395","65.2","58.8","11.1","88.2","26.7","1125.9","1109.9","0.7","0.0","0.00","0.000","0.0"," ","","2.5        ",""," Brown +  Gray silty CLAY little sand trace gravel moist CL                                                                                                                                                                                                   ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  8. "74550 12   7",74550,"12   ","7   ","2009-12-17","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","","","TEST SAMPLE                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
  9.  

2nd sample data set
Expand|Select|Wrap|Line Numbers
  1. "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
  2. "74547 1    3",74547,"1    ","3   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown and Gray silty CLAY                                                                                                                                                                                                                                    ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  3. "74547 1    4",74547,"1    ","4   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown SILT                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  4. "74547 2    3",74547,"2    ","3   ","2009-12-21","","","32 ","54.2","44.7","10.3","27.6","44.5","1215.2","1193.1","96.5","0.0","0.00","0.000","0.0"," ","","","Corrected"," Brown clayey SAND trace gravel moist SC                                                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  5. "74547 3    3",74547,"3    ","3   ","2009-12-21","","","33 ","56.9","49.6","9.9","18.4","44.3","1213.3","1192.5","52.7","0.0","0.00","0.000","0.0"," ","","4.5+       ","Corrected"," Black silty CLAY little sand trace GRAVEL trace organic moist CL - FILL                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  6. "74547 4    3",74547,"4    ","3   ","2009-12-21","","","34 ","57.7","48.6","10.2","23.7","38.6","1210.8","1191.9","50.4","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand moist CL                                                                                                                                                                                                                ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  7. "74547 5    3",74547,"5    ","3   ","2009-12-21","","","35 ","61.4","54.3","10.1","16.1","34.4","1206.8","1191.2","53.7","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand trace gravel trace organic moist CL                                                                                                                                                                                     ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  8. "74547 6    3",74547,"6    ","3   ","2009-12-21","","","36 ","58.9","51.0","9.9","19.2","44.1","1210.9","1190.4","52.3","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown silty CLAY little sand moist CL                                                                                                                                                                                                                        ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
  9.  
In my code below I can create the jobObject and a variable number of borings. But my "z" variable for creating the samples simply changes the existing sample on each loop.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. var JobObject = new createJobObj(aReturn)
  2.  
  3. function createJobObj(aData)
  4. {
  5.     //clientInfo
  6.     this.client = aData[0];
  7.     //jobInfo
  8.     this.job = aData[1]; 
  9.  
  10.     /*
  11.     ---------------------------------
  12.     create a boring array with sample 
  13.     data for each boring
  14.     ---------------------------------
  15.     */
  16.     this.boring = new Object();
  17.  
  18.  
  19.     for (var i = 2; i < aData.length; i++ )
  20.     {
  21.         var x = aData[i].substr(0,aData[i].indexOf('~'));
  22.  
  23.         if (x != this.boring)
  24.         {
  25.             this.boring[x] = new Object();
  26.         }
  27.  
  28.         //add sample data to boring element
  29.         aZ = new Array()
  30.         aZ = aData[i].split('~');
  31.         var z = aZ[1];
  32.  
  33.         if (z != this.boring[x])
  34.         {
  35.             this.boring[x][z] = new Object();
  36.         }
  37.         this.boring[x][z].sampleDate = aZ[2];
  38.         this.boring[x][z].depth = aZ[3];
  39.         this.boring[x][z].blows = aZ[4];
  40.         this.boring[x][z].contNumb = aZ[5];
  41.         this.boring[x][z].WWofSC = aZ[6];
  42.         this.boring[x][z].DWofSC = aZ[7];
  43.         this.boring[x][z].contWeight = aZ[8];
  44.         this.boring[x][z].moisture = aZ[9];
  45.         this.boring[x][z].sampleInAir = aZ[10];
  46.         this.boring[x][z].sampleInWater = aZ[11];
  47.         this.boring[x][z].water = aZ[12];
  48.         this.boring[x][z].dryUnit = aZ[13];
  49.         this.boring[x][z].corrected = aZ[14];
  50.         this.boring[x][z].dimDryUnit = aZ[15];
  51.         this.boring[x][z].dimCorrected = aZ[16];
  52.         this.boring[x][z].qu = aZ[17];
  53.         this.boring[x][z].qp = aZ[18];
  54.         this.boring[x][z].soilDesc = aZ[19];
  55.     }
  56. }
  57.  
Jan 4 '10 #1

✓ answered by Dormilich

I think it’s line 23. you check, whether this.boring equals x, but you certainly mean, whether x is a subobject of this.boring. (same goes for line 33)

there are 2 ways on my mind:
Expand|Select|Wrap|Line Numbers
  1. if (!(x in this.boring)) {}
  2. if (!this.boring[x]) {} // except if this.boring[x] may be 0, "", false, null, [] or {}

Share this Question
Share on Google+
4 Replies


Dormilich
Expert Mod 5K+
P: 8,639
I think it’s line 23. you check, whether this.boring equals x, but you certainly mean, whether x is a subobject of this.boring. (same goes for line 33)

there are 2 ways on my mind:
Expand|Select|Wrap|Line Numbers
  1. if (!(x in this.boring)) {}
  2. if (!this.boring[x]) {} // except if this.boring[x] may be 0, "", false, null, [] or {}
Jan 4 '10 #2

Claus Mygind
100+
P: 571
Of course you are correct, I am looking for a subObject. I had to run the simulation several times before I saw that my problem occurred on line 23.

I don't seem to be experiencing the problem on line 33 as you suggested and I was having some trouble implementing your suggestions (I believe you say I should use your line #2?

I am not clear on how I should test for the exceptions you have listed. And on the first go around the subObject has no properties so of course it crashes.
Jan 4 '10 #3

Claus Mygind
100+
P: 571
I see my error. Just repeat your line 1 on my line 33

Expand|Select|Wrap|Line Numbers
  1. if (!(z in this.boring[x]))
  2.  
Jan 4 '10 #4

Dormilich
Expert Mod 5K+
P: 8,639
I believe you say I should use your line #2?
no, both basicly (see comment) do the same.

and to be precise, your problem has nothing to do with inheritance, that would involve meddling with the prototype property.
Jan 4 '10 #5

Post your reply

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