Hi everybody.
I've discovered the following problem while building an APP:
/* Code Start *************** ***********/
// Definition
function cClass_prototyp e_prototype()
{
this.array = new Array;
this.className = "cClass_prototy pe_prototype";
}
function cClass_prototyp e()
{
this.className = "cClass_prototy pe";
}
cClass_prototyp e.prototype = new cClass_prototyp e_prototype;
function cClass1()
{
this.className = "cClass1";
}
function cClass2()
{
this.className = "cClass2";
}
cClass1.prototy pe = new cClass_prototyp e;
cClass2.prototy pe = new cClass_prototyp e;
oClass1 = new cClass1();
oClass2 = new cClass2();
// Testing
alert(oClass1.a rray)
alert(oClass2.a rray)
oClass1.array.p ush(1);
alert(oClass1.a rray)
alert(oClass2.a rray)
/* Code End *************** *************/
If you will execute this code you will see that pushing an value into
the first class instance array property cause changing value of the
second class instance array property.
Is it possible to have array values not connected to each other?
I would like to avoid defining "array" property in cClass1 and cClass2
(in this case it would work the proper way) and have them defined only
in third-level parent class cClass_prototyp e_prototype.
I've discovered the following problem while building an APP:
/* Code Start *************** ***********/
// Definition
function cClass_prototyp e_prototype()
{
this.array = new Array;
this.className = "cClass_prototy pe_prototype";
}
function cClass_prototyp e()
{
this.className = "cClass_prototy pe";
}
cClass_prototyp e.prototype = new cClass_prototyp e_prototype;
function cClass1()
{
this.className = "cClass1";
}
function cClass2()
{
this.className = "cClass2";
}
cClass1.prototy pe = new cClass_prototyp e;
cClass2.prototy pe = new cClass_prototyp e;
oClass1 = new cClass1();
oClass2 = new cClass2();
// Testing
alert(oClass1.a rray)
alert(oClass2.a rray)
oClass1.array.p ush(1);
alert(oClass1.a rray)
alert(oClass2.a rray)
/* Code End *************** *************/
If you will execute this code you will see that pushing an value into
the first class instance array property cause changing value of the
second class instance array property.
Is it possible to have array values not connected to each other?
I would like to avoid defining "array" property in cClass1 and cClass2
(in this case it would work the proper way) and have them defined only
in third-level parent class cClass_prototyp e_prototype.
Comment