Discussion:
trapped with inheritance
(too old to reply)
Claus Mygind
2008-11-24 19:42:22 UTC
Permalink
I don't know how to get myself out of this jam. This is a little
javascript, in this case not too different than dBase I suspect.

Basically I create an object load it with properties that each have values.
I then store the information of the object I just created into an array of
objects (which really is just an associtive array).

Now here is where the problem comes in. I want to cycle around and reuse
the original object. So I clear it out. And when I do that the values in
the array are also cleared out. Here is my code if someone could give a
suggestion.

var dDept = new Object();
var vDept = aPhaseCodes[0].substring(0,4);

var pOptions = new Array();
for (var i = 0; i < aPhaseCodes.length; i++ )
{
var pCode = aPhaseCodes[i].substring(5,7);

if (vDept == aPhaseCodes[i].substring(0,4))
{
pOptions[pOptions.length] = {value:pCode,text:pCode};
}else{

dDept[vDept] = pOptions;

///problem occurs here
pOptions.length = 0;
/*
after this step the information I just stored in the line above is also
wiped out.
*/


vDept = aPhaseCodes[i].substring(0,4);
pOptions[pOptions.length] = {value:pCode,text:pCode};
}
}
dDept[vDept] = pOptions;
Geoff Wass [dBVIPS]
2008-11-25 05:41:40 UTC
Permalink
Post by Claus Mygind
I don't know how to get myself out of this jam. This is a little
javascript, in this case not too different than dBase I suspect.
Basically I create an object load it with properties that each have values.
I then store the information of the object I just created into an array of
objects (which really is just an associtive array).
Now here is where the problem comes in. I want to cycle around and reuse
the original object. So I clear it out. And when I do that the values in
the array are also cleared out. Here is my code if someone could give a
suggestion.
var dDept = new Object();
var vDept = aPhaseCodes[0].substring(0,4);
var pOptions = new Array();
for (var i = 0; i < aPhaseCodes.length; i++ )
{
var pCode = aPhaseCodes[i].substring(5,7);
if (vDept == aPhaseCodes[i].substring(0,4))
{
pOptions[pOptions.length] = {value:pCode,text:pCode};
}else{
dDept[vDept] = pOptions;
///problem occurs here
pOptions.length = 0;
/*
after this step the information I just stored in the line above is also
wiped out.
*/
vDept = aPhaseCodes[i].substring(0,4);
pOptions[pOptions.length] = {value:pCode,text:pCode};
}
}
dDept[vDept] = pOptions;
Claus,

I am not very knowledgeable in Javascript, but

pOptions.length = 0;

is making pOptions an empty array (ie. it has NO elements). So, if you
don't want your array to disappear, don't do that! <bg>
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada

.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Claus Mygind
2008-11-26 12:58:10 UTC
Permalink
Geoff

Thanks for the response. As it turns out I will not need this process after
all so any discussion is purely academic now. Yes I realize that is the
problem as the array inherited the value. My problem was, I was using it in
a loop and needed to refresh the variable each time through the loop. So I
was caught in a catch 22 where if I did not refresh then all entries in the
array had the same values and if I do refresh then all the entries had no
value.

Claus
Post by Geoff Wass [dBVIPS]
Post by Claus Mygind
I don't know how to get myself out of this jam. This is a little
javascript, in this case not too different than dBase I suspect.
Basically I create an object load it with properties that each have values.
I then store the information of the object I just created into an array of
objects (which really is just an associtive array).
Now here is where the problem comes in. I want to cycle around and reuse
the original object. So I clear it out. And when I do that the values in
the array are also cleared out. Here is my code if someone could give a
suggestion.
var dDept = new Object();
var vDept = aPhaseCodes[0].substring(0,4);
var pOptions = new Array();
for (var i = 0; i < aPhaseCodes.length; i++ )
{
var pCode = aPhaseCodes[i].substring(5,7);
if (vDept == aPhaseCodes[i].substring(0,4))
{
pOptions[pOptions.length] = {value:pCode,text:pCode};
}else{
dDept[vDept] = pOptions;
///problem occurs here
pOptions.length = 0;
/*
after this step the information I just stored in the line above is also
wiped out.
*/
vDept = aPhaseCodes[i].substring(0,4);
pOptions[pOptions.length] = {value:pCode,text:pCode};
}
}
dDept[vDept] = pOptions;
Claus,
I am not very knowledgeable in Javascript, but
pOptions.length = 0;
is making pOptions an empty array (ie. it has NO elements). So, if you
don't want your array to disappear, don't do that! <bg>
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada
.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Geoff Wass [dBVIPS]
2008-11-27 05:50:29 UTC
Permalink
Post by Claus Mygind
Geoff
Thanks for the response. As it turns out I will not need this process after
all so any discussion is purely academic now. Yes I realize that is the
problem as the array inherited the value. My problem was, I was using it in
a loop and needed to refresh the variable each time through the loop. So I
was caught in a catch 22 where if I did not refresh then all entries in the
array had the same values and if I do refresh then all the entries had no
value.
Claus
Claus,

Just so you know, what you were doing was refreshing the array and then
killing it. If you removed that one line it would have been fine, I
think.
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada

.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Claus Mygind
2008-11-29 23:19:42 UTC
Permalink
Post by Geoff Wass [dBVIPS]
Post by Claus Mygind
Geoff
Thanks for the response. As it turns out I will not need this process after
all so any discussion is purely academic now. Yes I realize that is the
problem as the array inherited the value. My problem was, I was using it in
a loop and needed to refresh the variable each time through the loop. So I
was caught in a catch 22 where if I did not refresh then all entries in the
array had the same values and if I do refresh then all the entries had no
value.
Claus
Claus,
Just so you know, what you were doing was refreshing the array and then
killing it. If you removed that one line it would have been fine, I
think.
Yes that is what I figured out and that is where the catch 22 came in. I
could not remove it because I needed an empty variable for the next time
through the loop.

Claus
Post by Geoff Wass [dBVIPS]
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada
.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Loading...