1. Object impersonating
Function classa (scolor ){
This. Color = scolor;
This. saycolor = function (){
Alert (this. Color );
}
}
Function classb (scolor, sname ){
This. newmethod = classa;
This. newmethod (scolor );
Delete this. newmethod;
This. Name = sname;
This. sayname = function (){
Alert (this. Name );
}
}
VaR objb = new classb ("color of objb", "Name of objb ");
Objb. saycolor ();
2. Call Method
Function classa (scolor ){
This. Color = scolor;
This. saycolor = function (){
Alert (this. Color );
}
}
Function classb (scolor, sname ){
// This. newmethod = classa;
// This. newmethod (scolor );
// Delete this. newmethod;
Classa. Call (this, scolor );
This. Name = sname;
This. sayname = function (){
Alert (this. Name );
}
}
VaR objb = new classb ("color of objb", "Name of objb ");
Objb. saycolor ();
3. Apply Method
Function classa (scolor ){
This. Color = scolor;
This. saycolor = function (){
Alert (this. Color );
}
}
Function classb (scolor, sname ){
// This. newmethod = classa;
// This. newmethod (scolor );
// Delete this. newmethod;
Classa. Apply (this, new array (scolor ));
This. Name = sname;
This. sayname = function (){
Alert (this. Name );
}
}
VaR objb = new classb ("color of objb", "Name of objb ");
Objb. saycolor ();
4. Prototype Chain Method
Function classa (){
}
Classa. Prototype. color = "color ";
Classa. Prototype. saycolor = function (){
Alert (this. Color );
}
Function classb (){
}
Classb. Prototype = new classa ();
Classb. Prototype. Name = "name ";
Classb. Prototype. sayname = function (){
Alert (this. Name );
}
VaR objb = new classb ();
Objb. color = "color of objb ";
Objb. Name = "Name of objb ";
Objb. saycolor ();
5. hybrid mode
Function classa (scolor ){
This. Color = scolor;
}
Classa. Prototype. saycolor = function (){
Alert (this. Color );
}
Function classb (scolor, sname ){
Classa. Call (this, scolor );
This. Name = sname;
}
Classb. Prototype = new classa ();
Classb. Prototype. sayname = function (){
Alert (this. Name );
}
VaR objb = new classb ("color of objb", "Name of objb ");
Objb. saycolor ();